-
-
Save Camwyn/ce34677cafe52d46c12c11c8b9119371 to your computer and use it in GitHub Desktop.
Limit Slider Revolution's WP_Query to only include Featured Events that have a featured image
This file contains hidden or 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 | |
/** | |
* Limit Slider Revolution's WP_Query to only include Featured Events that have a featured image | |
* | |
* @link https://theeventscalendar.com/knowledgebase/k/integrating-the-events-calendar-with-slider-revolution-and-essential-grid/ | |
* | |
* Based on https://gist.github.com/cliffordp/30ac2152a8264ef27235b46b7d16332d | |
* Similar code for Essential Grid: https://gist.github.com/Camwyn/15e1936639a5ea7b1575b35f252ebd40 | |
* Same Slider Revolution code except without requirement for being a Featured Event (works for more than just The Events Calendar): https://gist.github.com/Camwyn/d7128fb83074d75e1562adac2735a834 | |
* | |
* Tested working with version 6.5.24 | |
* | |
* `revslider_get_posts` filter is from plugins/revslider/includes/slider.class.php as of version 6.5.24 | |
* | |
* Filter hook only applies to Slider Revolution > Post-Based Slider > Fetch Posts By Categories & Tags | |
* or Slider Revolution > Post-Based Slider > Specific Posts > Specific Posts List (CSV of Post IDs) | |
* There are others in plugins/revslider/includes/slider.class.php for other queries. | |
* | |
* @return array | |
*/ | |
function revslider_post_based_featured_events_w_featured_image( $query, $slider_id ) { | |
/* YOU MUST CHANGE THESE TO YOUR OWN SLIDER REVOLUTION SLIDER IDs!!! */ | |
$slider_ids_to_affect = [ 2, 20, 34 ]; // include IDs of sliders to affect | |
// If this slider is not one we want to affect, bail. | |
if ( ! isset( $slider_id, array_reverse( $slider_ids_to_affect ) ) ) { | |
return $query; | |
} | |
// Get the existing meta_query so we aren't wiping that out. | |
if ( ! empty( $query['meta_query'] ) ) { | |
$meta_query = (array) $query[ 'meta_query' ]; | |
} else { | |
$meta_query = []; | |
} | |
// do the filtering... | |
// Restrict to events(posts) that have a featured image. | |
$meta_query[] = [ | |
'compare' => 'BETWEEN', | |
'key' => '_thumbnail_id', | |
'value' => [ 1, PHP_INT_MAX ], | |
]; | |
// Restrict to events(posts) that have are featured events. | |
if ( class_exists( 'Tribe__Events__Main' ) | |
&& class_exists( 'Tribe__Events__Featured_Events' ) | |
&& in_array( Tribe__Events__Main::POSTTYPE, (array) $query['post_type'] ) | |
) { | |
$meta_query[] = [ | |
'key' => Tribe__Events__Featured_Events::FEATURED_EVENT_KEY, | |
'compare' => 'EXISTS', | |
]; | |
} | |
$query['meta_query'] = $meta_query; | |
return $query; | |
} | |
add_filter( 'revslider_get_posts', 'revslider_post_based_featured_events_w_featured_image', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment