Ticket #561: 561.3.diff
File 561.3.diff, 4.1 KB (added by , 11 years ago) |
---|
-
.
-
plugins/wc-post-types/wc-post-types.php
Property changes on: . ___________________________________________________________________ Added: svn:ignore ## -0,0 +1 ## +upgrade
256 256 'posts_per_page' => -1, 257 257 'orderby' => 'date', 258 258 'order' => 'desc', 259 'track' => 'all', 259 260 ), $attr ); 260 261 261 262 $attr['show_avatars'] = $this->str_to_bool( $attr['show_avatars'] ); 262 263 $attr['orderby'] = ( in_array( $attr['orderby'], array( 'date', 'title', 'rand' ) ) ) ? $attr['orderby'] : 'date'; 263 264 $attr['order'] = ( in_array( $attr['order'], array( 'asc', 'desc') ) ) ? $attr['order'] : 'desc'; 264 265 265 $speakers = new WP_Query( array( 266 'post_type' => 'wcb_speaker', 267 'posts_per_page' => intval( $attr['posts_per_page'] ), 268 'orderby' => $attr['orderby'], 269 'order' => $attr['order'], 270 ) ); 266 // Get track slugs and set transient key 267 $track_slugs = $attr['track']; 268 $transient_key = 'speaker_ids_' . md5( $track_slugs ); 271 269 270 // Get saved speaker IDs if transient exists 271 $speaker_ids = get_transient( $transient_key ); 272 273 if( ! $speaker_ids ) { 274 275 // Fetch all sessions 276 $session_args = array( 277 'post_type' => 'wcb_session', 278 'posts_per_page' => -1, 279 ); 280 281 // Filter by track if specified 282 if( 'all' != $track_slugs ) { 283 $session_args['tax_query'] = array( 284 array( 285 'taxonomy' => 'wcb_track', 286 'field' => 'slug', 287 'terms' => explode( ',', $track_slugs ), 288 ), 289 ); 290 } 291 292 // Get all relevant sessions 293 $sessions = get_posts( $session_args ); 294 295 // Get array of relevant speaker IDs 296 $speaker_ids = array(); 297 foreach ( $sessions as $session ) { 298 $session_speaker_ids = get_post_meta( $session->ID, '_wcpt_speaker_id' ); 299 $speaker_ids = array_merge( $speaker_ids, $session_speaker_ids ); 300 } 301 302 // Set transient with speaker IDs to prevent long page load times 303 set_transient( $transient_key, $speaker_ids, HOUR_IN_SECONDS ); 304 } 305 306 // Fetch all specified speakers 307 $speaker_args = array( 308 'post_type' => 'wcb_speaker', 309 'posts_per_page' => intval( $attr['posts_per_page'] ), 310 'post__in' => $speaker_ids, 311 'orderby' => $attr['orderby'], 312 'order' => $attr['order'], 313 ); 314 315 $speakers = new WP_Query( $speaker_args ); 316 272 317 if ( ! $speakers->have_posts() ) 273 318 return ''; 274 319 … … 279 324 280 325 <?php while ( $speakers->have_posts() ) : $speakers->the_post(); ?> 281 326 282 <div id="wcorg-speaker-<?php echo sanitize_html_class( $post->post_name ); ?>" class="wcorg-speaker"> 327 <?php 328 // Get list of speaker tracks for div class 329 $tracks = get_post_meta( get_the_ID(), '_wcpt_speaker_tracks', false ); 330 $track_class = ''; 331 foreach( $tracks as $track ) { 332 $track_class .= ' ' . sanitize_html_class( $track ); 333 } 334 ?> 335 336 <div id="wcorg-speaker-<?php echo sanitize_html_class( $post->post_name ); ?>" class="wcorg-speaker<?php echo $track_class; ?>"> 283 337 <h2><?php the_title(); ?></h2> 284 338 <div class="wcorg-speaker-description"> 285 339 <?php echo ( $attr['show_avatars'] ) ? get_avatar( get_post_meta( get_the_ID(), '_wcb_speaker_email', true ), absint( $attr['avatar_size'] ) ) : ''; ?> 286 340 <?php the_content(); ?> 287 341 </div> 288 </div> 342 </div><!-- .wcorg-speaker --> 289 343 290 344 <?php endwhile; ?> 291 345 … … 293 347 <?php 294 348 295 349 wp_reset_postdata(); 296 $content = ob_get_contents(); 297 ob_end_clean();350 351 $content = ob_get_clean(); 298 352 return $content; 299 353 } 300 354 -
themes