• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WP SITES

2785

Original Genesis & WooCommerce Tutorials & 6000+ Guaranteed Code

Snippets

  • Try Premium
  • Log in

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

  • Genesis Featured Posts Pro Widget

Genesis Featured Posts

Reader Interactions

Comments

  1. Cemal Ekin says

    March 24, 2019 at 1:45 pm

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

    Log in to Reply

Leave a Reply Cancel reply

You must be logged in to post a comment.

Primary Sidebar

Code written by Brad Dalton specialist for Genesis, WooCommerce & WordPress theme customization. Read More…

Advertise · WPEngine · Genesis · Log in

  • Access Problems
  • Account Details
  • Consulting
  • Tags