Skip to content

Instantly share code, notes, and snippets.

@tomhemsley
Created July 18, 2014 10:47
Show Gist options
  • Save tomhemsley/100930dafd179bae2d1d to your computer and use it in GitHub Desktop.
Save tomhemsley/100930dafd179bae2d1d to your computer and use it in GitHub Desktop.
Meta Slider Post Feed - Restrict to current category
/**
* Alter the post feed query arguments to restrict the results to posts
* tagged to the current category.
*
* REQUIRES: Meta Slider Pro 2.4.5+
*/
function metaslider_restrict_to_current_category( $args, $slide, $slider_settings, $slide_settings ) {
// check slide ID so we only apply this functionality where it's needed
if ( $slide->ID == 101 && is_category() ) {
// remove any existing restrictions
if ( isset ( $args['tax_query'] ) ) {
unset( $args['tax_query'] );
}
// restrict to posts tagged to the current category
$args['tax_query'][] = array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => get_query_var( 'cat' )
);
}
return $args;
}
add_filter( 'metaslider_post_feed_args', 'metaslider_restrict_to_current_category', 10, 4);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment