Changeset 11352 for sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/functions.php
- Timestamp:
- 12/02/2021 12:59:04 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/functions.php
r11336 r11352 166 166 167 167 /** 168 * Get the values associated to the page/post 168 * Get the values associated to the page/post formatted as a string 169 169 * 170 170 * @param string $post_id Id of the post. … … 180 180 181 181 /** 182 * Get the values associated to the page/post formatted as an array 183 * 184 * @param string $post_id Id of the post. 185 * @param string $tax_slug The slug for the custom taxonomy. 186 * 187 * @return array 188 */ 189 function wporg_learn_get_taxonomy_terms_array( $post_id, $tax_slug ) { 190 $term_ids = wp_get_post_terms( $post_id, $tax_slug, array( 'fields' => 'ids' ) ); 191 192 $terms = array(); 193 foreach ( $term_ids as $id ) { 194 $terms[ $id ] = get_term( $id )->name; 195 } 196 197 return $terms; 198 } 199 200 /** 201 * Get the values associated to the page/post according to the context 202 * 203 * @param int $post_id ID of the post. 204 * @param string $tax_slug The slug for the custom taxonomy. 205 * @param string $context The context for display. 206 * 207 * @return array|string 208 */ 209 function wporg_learn_get_taxonomy_terms( $post_id, $tax_slug, $context ) { 210 switch ( $context ) { 211 case 'archive': 212 return wporg_learn_get_taxonomy_terms_string( $post_id, $tax_slug ); 213 break; 214 case 'single': 215 return wporg_learn_get_taxonomy_terms_array( $post_id, $tax_slug ); 216 break; 217 } 218 } 219 220 /** 182 221 * Returns the taxonomies associated to a lesson or workshop 183 222 * … … 186 225 * @return array 187 226 */ 188 function wporg_learn_get_lesson_plan_taxonomy_data( $post_id ) {227 function wporg_learn_get_lesson_plan_taxonomy_data( $post_id, $context ) { 189 228 return array( 190 229 array( 191 230 'icon' => 'clock', 231 'slug' => 'duration', 192 232 'label' => wporg_label_with_colon( get_taxonomy_labels( get_taxonomy( 'duration' ) )->singular_name ), 193 'value' => wporg_learn_get_taxonomy_terms _string( $post_id, 'duration'),233 'value' => wporg_learn_get_taxonomy_terms( $post_id, 'duration', $context ), 194 234 ), 195 235 array( 196 236 'icon' => 'admin-users', 237 'slug' => 'audience', 197 238 'label' => wporg_label_with_colon( get_taxonomy_labels( get_taxonomy( 'audience' ) )->singular_name ), 198 'value' => wporg_learn_get_taxonomy_terms _string( $post_id, 'audience'),239 'value' => wporg_learn_get_taxonomy_terms( $post_id, 'audience', $context ), 199 240 ), 200 241 array( 201 242 'icon' => 'dashboard', 243 'slug' => 'level', 202 244 'label' => wporg_label_with_colon( get_taxonomy_labels( get_taxonomy( 'level' ) )->singular_name ), 203 'value' => wporg_learn_get_taxonomy_terms _string( $post_id, 'level'),245 'value' => wporg_learn_get_taxonomy_terms( $post_id, 'level', $context ), 204 246 ), 205 247 array( 206 248 'icon' => 'welcome-learn-more', 249 'slug' => 'type', 207 250 'label' => wporg_label_with_colon( get_taxonomy_labels( get_taxonomy( 'instruction_type' ) )->singular_name ), 208 'value' => wporg_learn_get_taxonomy_terms _string( $post_id, 'instruction_type'),251 'value' => wporg_learn_get_taxonomy_terms( $post_id, 'instruction_type', $context ), 209 252 ), 210 253 ); … … 301 344 if ( $query->is_main_query() && $query->is_search() ) { 302 345 $public_post_types = array_keys( get_post_types( array( 'public' => true ) ) ); 303 $omit_from_search = array( 'attachment', ' lesson', 'quiz', 'sensei_message', 'meeting' );346 $omit_from_search = array( 'attachment', 'page', 'lesson', 'quiz', 'sensei_message', 'meeting' ); 304 347 $searchable_post_types = array_diff( $public_post_types, $omit_from_search ); 348 349 // Only show featured courses, but don't limit other post types 350 $query->set( 351 'meta_query', 352 array( 353 'relation' => 'OR', 354 array( 355 'key' => '_course_featured', 356 'value' => 'featured', 357 ), 358 array( 359 'key' => '_course_featured', 360 'compare' => 'NOT EXISTS', 361 ), 362 ) 363 ); 305 364 306 365 $query->set( 'post_type', $searchable_post_types ); … … 564 623 565 624 case 'lesson-plan': 566 $args['meta'] = wporg_learn_get_lesson_plan_taxonomy_data( $post_id );625 $args['meta'] = wporg_learn_get_lesson_plan_taxonomy_data( $post_id, 'archive' ); 567 626 break; 568 627
Note: See TracChangeset
for help on using the changeset viewer.