How to exclude Posts having a specific tag from Genesis Featured Posts

In GenesisWP Slack channel, a user asked:

Using the inbuilt Genesis Featured Posts, is there a way to exclude a specific tag from the results? Wondering if there’s a way using pre_get_posts…

So posts with a specific tag don’t show in genesis featured post widgets.

This can be done using Custom Genesis Featured Posts Widget plugin.

Step 1

Install and activate Custom Genesis Featured Posts Widget plugin.

Step 2

Modify plugin’s class-custom-featured-post.php.

Locate

$query_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'],
);

and add tag__not_in like so:

$query_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'],
    'tag__not_in'         => array( 24 ),
);

where 24 is the ID of the tag to be excluded from the Genesis Featured Posts.

That’s it.

[post_tags] shortcode can be used to display tags in the plugin’s widget settings.

This site uses cookies to offer you a better browsing experience. By browsing this website, you agree to our use of cookies.