0

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.

asked May 27, 2024 at 13:51
3
  • "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. Commented 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. Commented 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/… Commented Jun 3, 2024 at 19:11

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.