我需要显示自定义分类页面上的特色帖子

时间:2018-11-30 作者:Om Pal

我需要在默认循环上方的自定义分类页面上显示特色帖子,但不显示特色帖子,而是显示所有帖子

$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();

1 个回复
SO网友:Aniruddha Gawade

元查询的语法似乎错误。就像税务查询一样,它应该是一个数组,每个元条件对应一个数组。同时使用$query 对于您的查询功能:

$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();

相关推荐