• I am trying to show the featured posts in my theme, with a custom field mytheme_featured_post which is 1 on the featured posts.

    However it does not seem to filter the posts down to only the posts in the meta query.

    // WP_Query arguments.
    $featured = array(
    'posts_per_page' => '5',
    'meta_query' => array(
        array(
            'key'     => 'mytheme_featured_post',
            'value'   => '1',
        ),
    ),
    );
    
    // The Query.
    $featured_query = new WP_Query( $featured );
    
    if ( $featured_query -> have_posts() ) {
        while ( $featured_query -> have_posts() ) : $featured_query -> the_post();
            the_title();
        endwhile;
    }
Viewing 1 replies (of 1 total)
  • If you want to show the featured posts of your theme, with a custom field mytheme_featured_post
    the below query you can try.

    <?php 
    
    $featured_query = new WP_query( array(
        'meta_key'       =>'mytheme_featured_post', 
        'meta_value'     =>'1', 
        'posts_per_page' => 5
        )
    );
    
    while ($featured_query->have_posts()) : $featured_query->the_post(); 
            the_title();
        //Stuff...
    
    endwhile; 
    wp_reset_postdata(); 
    
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Second loop showing posts from main query’ is closed to new replies.