rycr
rycr

Reputation: 3

How to hide Featured Posts in Wordpress Loop

I'm using the plugin "Featured Posts" to set featured posts. (plugin link https://wordpress.org/plugins/featured-post/)

I'm displaying featured posts at the top of my homepage, then displaying a list of blog posts at the bottom. However, I don't want featured posts from the top to be repeated in the bottom section.

Can anyone offer guidance on how to exclude featured posts from the loop? I realize I could just add a 'featured' category and exclude from the loop, but I really want to figure this out.

Upvotes: 0

Views: 1743

Answers (1)

Becks
Becks

Reputation: 11

It looks like the plugin uses meta keys to mark posts as featured, so you could try using a custom query and exclude posts where that meta key (_is_featured) is set to "yes" like this:

$args = array(
    'post_type'  => 'post',
    'posts_per_page'=>-1,
    'meta_query' => array(
        array(
            'key'     => '_is_featured',
            'value'   => 'yes',
            'compare' => 'NOT LIKE',
        ),
    ),
);
$query = new WP_Query( $args );

You could then run through this loop like so:

if ( $query->have_posts() ) {
    while ( $query->have_posts() ) {
        $query->the_post();
        // display the post here
    }
} else {
    // no posts found
}

https://codex.wordpress.org/Class_Reference/WP_Query

Upvotes: 1

Related Questions