i need to show featured post on custom taxonomy page

admin2025-06-05  2

i need to show featured post on custom taxonomy page above default loop but not showing feature post its showing all post

$args = array(
            'posts_per_page' => 3,
            'post_type' => 'post',
            'tax_query' => array(
                array(   
                    'taxonomy' => 'city',
                    'field' => 'term_id',  

                ),

             ),

            'meta_query' => array(
                         'key' => 'is_this_featured',
                         'value' => 'yes',
                         'compare' => 'LIKE',
                     ),

         );

$query = new WP_Query( $args ); 

if ( have_posts() ) :
    while ( have_posts() ) : the_post();
        // $ids[] = get_the_ID();
        the_title();
        the_content();
    endwhile;
endif;
wp_reset_query();

i need to show featured post on custom taxonomy page above default loop but not showing feature post its showing all post

$args = array(
            'posts_per_page' => 3,
            'post_type' => 'post',
            'tax_query' => array(
                array(   
                    'taxonomy' => 'city',
                    'field' => 'term_id',  

                ),

             ),

            'meta_query' => array(
                         'key' => 'is_this_featured',
                         'value' => 'yes',
                         'compare' => 'LIKE',
                     ),

         );

$query = new WP_Query( $args ); 

if ( have_posts() ) :
    while ( have_posts() ) : the_post();
        // $ids[] = get_the_ID();
        the_title();
        the_content();
    endwhile;
endif;
wp_reset_query();
Share Improve this question edited Nov 30, 2018 at 10:44 Aniruddha Gawade 1,2131 gold badge10 silver badges12 bronze badges asked Nov 30, 2018 at 8:32 Om PalOm Pal 11 bronze badge 1
  • You can try using suppress_filters => true param in your WP_Query args list – vikrant zilpe Commented Nov 30, 2018 at 10:54
Add a comment  | 

1 Answer 1

Reset to default 0

Syntax for your meta query seems to be wrong. Just as tax query, it should be array with array for each meta condition. Also use $query for your query functions:

$args = array(
            'posts_per_page' => 3,
            'post_type' => 'post',
            'tax_query' => array(
                array(   
                    'taxonomy' => 'city',
                    'field' => 'term_id',  

                ),

             ),

            'meta_query' => array(
                 array(
                         'key' => 'is_this_featured',
                         'value' => 'yes',
                         'compare' => 'LIKE',
                     ),
             ),

         );

$query = new WP_Query( $args ); 

if ( $query->have_posts() ) :
    while ( $query->have_posts() ) : $query->the_post();
        // $ids[] = get_the_ID();
        the_title();
        the_content();
    endwhile;
endif;
wp_reset_query();
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749138676a316688.html

最新回复(0)