Add Filter To WP_Query In Genesis Featured Posts Widget – Suggested Genesis Core Enhancement

This enhancement would enable Genesis users to filter the WP_Query arguments ( $query_args ) used in the Genesis Featured Posts widget.

WARNING : It is not recommended to edit files which are part of the core Genesis Framework under any circumstances. This is a suggested enhancement to the featured posts widget in the Genesis core files.

In genesis > lib > widgets > featured-post-widget.php on line 106, the suggested filter would be added to the code something like this :

$query_args = apply_filters( 'featured_posts_args', array(  
	'post_type'           => 'post',
	'cat'                 => $instance['posts_cat'],
	'showposts'           => $instance['posts_num'],
	'offset'              => $instance['posts_offset'],
	'orderby'             => $instance['orderby'],
	'order'               => $instance['order'],
	'ignore_sticky_posts' => $instance['exclude_sticky'],
) );

This adds a filter named featured_posts_args which you can then use in your child themes functions file like this :

add_filter( 'featured_posts_args', 'exclude_category_featured_posts' );
function exclude_category_featured_posts( $args ) {
$args['category__not_in'] = array( '9' );
return $args;
}

The above filter function enables you to modify any of the WP_Query arguments used in the featured posts widget. In this case, it excludes posts in category 9 from showing in the widget.

Is there any reason this filter should not or cannot be added to Genesis? Let me know in the comments if you have any feedback or suggestions…

Related Tutorials


Comments

One response to “Add Filter To WP_Query In Genesis Featured Posts Widget – Suggested Genesis Core Enhancement”

  1. Cemal Ekin Avatar
    Cemal Ekin

    This is a great idea. I was looking for a way to exclude a category and found this.

Leave a Reply

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.