WP Query taxonomy in two different custom fields
-
I’ve got a custom post type (book) and a taxonomy (person). The post type has two different custom fields of the type “advanced taxonomy”, both with the same taxonomy “person”. One field is called “published” and one “has_text”. Both fields have the same taxonomy so that they share the same pool of persons. In both fields there can be chosen more than one taxonomy term.
In my wp query I don’t know how to deal with it. On “site.com/person/max” I would like to show all books that habe the term “max”(id: 10) in the field “published”. I tried two different ways. Both don’t work.
$args = [ 'posts_per_page' => -1, 'meta_query' => [], 'post_type' => 'book', 'order' => 'DESC', 'orderby'=> 'date', 'tax_query' => array( array ( 'taxonomy' => 'published', 'field' => 'term_id', 'terms' => '10', ) ), ];
'meta_query' => array( array( 'key' => 'published', 'value' => '10', 'compare' => 'IN', 'type' => 'term_id', ))
The first one shows all books, the second one just the books that ONLY have the term_id 10, not those which also have other publishers.
- You must be logged in to reply to this topic.