Created
February 21, 2016 20:02
-
-
Save jbrinley/65688dbb469a78939ee1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'tribe_get_list_widget_events', 'cc_tribe_get_list_widget_events' ); | |
function cc_tribe_get_list_widget_events( $posts ) { | |
$output_posts = []; | |
$used_posts = []; | |
$query = new WP_Query([ | |
'eventDisplay' => 'list', | |
'posts_per_page' => 3, | |
'tribe_render_context' => 'widget', | |
'meta_query' => [ | |
'featured' => [ | |
'key' => 'featured', | |
'value' => 'yes', | |
], | |
], | |
]); | |
foreach( $query->posts as $post ) { | |
$output_posts[] = $post; | |
$used_posts[] = $post->ID; | |
} | |
if ( count( $output_posts ) < 3 ) { | |
$query = new WP_Query([ | |
'eventDisplay' => 'list', | |
'posts_per_page' => 3, | |
'tribe_render_context' => 'widget', | |
'post__not_in' => $used_posts, | |
'meta_query' => [ | |
'linked' => [ | |
'key' => 'link_url', | |
'compare' => '!=', | |
'value' => '', | |
], | |
], | |
]); | |
foreach( $query->posts as $post ) { | |
if ( count( $output_posts ) >= 3 ) { | |
break; | |
} | |
$output_posts[] = $post; | |
$used_posts[] = $post; | |
} | |
} | |
if ( count( $output_posts ) < 3 ) { | |
$query = new WP_Query([ | |
'eventDisplay' => 'list', | |
'posts_per_page' => 3, | |
'tribe_render_context' => 'widget', | |
'post__not_in' => $used_posts, | |
]); | |
foreach( $query->posts as $post ) { | |
if ( count( $output_posts ) >= 3 ) { | |
break; | |
} | |
$output_posts[] = $post; | |
$used_posts[] = $post; | |
} | |
} | |
return $output_posts; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment