php - using in_category rather than query_posts in wordpress -


in wordpress have page template called news want display posts 1 category - 'news'. don't want use category.php because there massive blog on site already.

 query_posts('cat=145');    while ( have_posts() ) : the_post();  //do  endwhile;  

works fine have read query_posts has drawbacks (like speed)

i tried doing showed me nothing:

while ( have_posts() ) : the_post(); if ( in_category( '145' ) ) : //also tried 'news' //do 

why doesn't' in_category work here?

please try code:

$args = array('post_type' => 'post',         'tax_query' => array(                 array(                         'taxonomy' => 'category',                         'field'    => 'slug',                         'terms'    => 'news'  // please pass here news category slugs                      ),                 )         );      $loop = new wp_query( $args );     while ( $loop->have_posts() ) : $loop->the_post();         print_r($post);     endwhile;      wp_reset_postdata(); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -