Fernando Souza
Fernando Souza

Reputation: 1779

Do wordpress loop with a specific term

How can I do the wordpress post loop, using a custom post type, to display only post from a certain category of a custom taxonomy?

$args = array(
    'post_type' => 'news',
    'taxonomy' => 'newscat',
    'field' => 'slug',
    'terms' => 'news',
    'posts_per_page' => 6,
);
$query = new WP_Query($args);
if($query -> have_posts()):while($query -> have_posts()):$query -> the_post();

Upvotes: 1

Views: 771

Answers (1)

shutupchigo
shutupchigo

Reputation: 713

Your arguments are incorrect.

Try this.

$args = array(
 'post_type' => 'news',
 'posts_per_page' => 6,
 'tax_query' => array(
    array(
     'taxonomy' => 'newscat',
     'field' => 'slug',
     'terms' => 'news'
  ),
 ),
);
$query = new WP_Query($args);
if($query -> have_posts()):while($query -> have_posts()):$query -> the_post();

Upvotes: 2

Related Questions