Blog

Stay connected to the latest UpdraftPlus news.

Description

Use this filter to modify the query arguments used to extract posts in a Post Feed slide.

Parameters

$args

(array) (required) WP_Query arguments as defined by the slide settings

$slide

(object) (required) Current slide data

$slider_settings

(array) (required) Current slider settings

$slide_settings

(array) (required) Current slide settings

Examples

The following code samples should be added to your theme’s functions.php file.

Display all posts tagged to the current category

Use this code to override the taxonomy restrictions defined in the slide settings, and instead extract all posts which are tagged to the current category. With this code in place you can create a single slideshow and add the Template Include to your category.php template. The slideshow will automatically show posts that are tagged to the current category.

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

    // replace "123" with the slide ID to target.

	if ( $slide->ID == 123 && 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);

 Display Sticky Posts only

function metaslider_post_feed_sticky( $args, $slide, $slider_settings, $slide_settings ) {
 
    // replace "735" with the slide ID to target.
    // get the slide ID by hovering over the delete icon and noting down the "deleteSlide" ID in the status bar
	if ( $slide->ID == 735 ) {
		$args['post__in'] = get_option('sticky_posts');
		$args['ignore_sticky_posts'] = true;
	}
 
	return $args;
}
add_filter( 'metaslider_post_feed_args', 'metaslider_post_feed_sticky', 10, 4);

 

Related Pages: