I've got a custom post type (book) and a taxonomy (person). The post type has two different custom taxonomy fields, both with the 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.
-
"The post type has two different custom taxonomy fields" you mean meta ? How a post have term field, You have person taxonomy with 2 fields published and has_text or they are terms ,or something else ? You mix meta , terms and taxonomy and its unclear what is the goal.Snuffy– Snuffy2024年05月27日 13:58:59 +00:00Commented May 27, 2024 at 13:58
-
I use Metabox and added different custom fields for the post type. Two of those custom fields are of the type "advanced taxonomy" of the taxonomy "person". It is important to have the same taxonomy for the two different custom fields because I use this taxonomy for other post types aswell and I want to have an overview of all the stuff a person is involved in.towelie– towelie2024年05月27日 14:13:46 +00:00Commented May 27, 2024 at 14:13
-
The problem was that the "advanced taxonomy" doesn't link the terms with the post directly as described here: wordpress.org/support/topic/…towelie– towelie2024年06月03日 19:11:30 +00:00Commented Jun 3, 2024 at 19:11