I have 2 queries, the first one is retrieving posts that have a meta_query key with the value of 1 and the second main loop is retrieving the latest posts.

I would like to exclude to exclude the featured posts from the second main loop.

First query

    $args = array(
        'post_type'              => array( 'post' ),
        'post_status'            => array( 'publish' ),
        'posts_per_page' => 2,
        'meta_query' => array(
                'key' => 'featured',
                'value' => 1
        )
    );

    $q = new WP_Query($args);

    if ($q->have_posts()): 
         while($q->have_posts()): 
             $q->the_post(); 
    $class = $q->current_post == 1 ? 'col-md-8' : 'col-md-4';

The second main query

    wp_reset_query();
    // WP_Query arguments
    $exclude_featured_args = array(
        'meta_query' => array(
            array(
                'key' => 'featured',
                'value' => 1,
                'compare' => '!='
            )
        )
    );

    $args = array(
        'post_type'              => array( 'post' ),
        'post_status'            => array( 'publish' ),
        'nopaging'               => false,
        'posts_per_page'         => 6
    );


    // The Query
    $query = new WP_Query( $args );

I tried to include the args of $exclude_featured_args in the second main loop but that didn’t work.

Read more here: Exclude posts from main loop with meta_query value in WordPress


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: