List Posts of a Custom Post Types Ordered by Terms of a Custom Taxonomy?

I’ve created a custom post type and custom taxonomy. I can now create a new post and associate it with a custom category.

The problem is listing these news post types.

Read More

This:

$loop = new WP_Query( array( 'post_type' => 'sobeedesce' ) );
while ( $loop->have_posts() ) : $loop->the_post();
  the_title();
  echo "<br />";
endwhile;`

lists all custom posts ok. But I want to list them by category, so adding 'cat' => 12 returns nothing.

I know my custom category id is 12 and I can confirm that by doing

$custom_terms = get_the_terms(0, 'cat_sd');
print_r($loop);`

inside the loop.

I’m missing something here. Can someone help me?
Thanks.

Related posts

Leave a Reply

1 comment

  1. I suppose your custom taxonomy slug is ‘cat_sd’, right?

    If so, the right query would be:

    $loop = new WP_Query( array( 'post_type' => 'sobeedesce', 'cat_sd' => 12 ) );