WordPress.org

Support

Support » Plugins and Hacks » WP_Query with cpt-onomies children terms

WP_Query with cpt-onomies children terms

  • Hello,
    I’ve a small problem.
    I want to display players from teams. Teams are cpt-onomies.
    Teams are hierarchical :

    Team A
    – 2013
    – 2012
    Team B
    – 2013
    – 2012

    Player A belongs to ‘Team A -> 2013’ but not to ‘Team A’ (checkbox is not checked).
    In databases, postmeta is right : only one instance of _custom_post_type_onomies_relationship with the id of the children term.

    But when I make a query with

    array(
       'taxonomy' => 'custom post type',
       'terms' => 'team-a',
       'field' => 'slug'
    );

    it returns me a list of players, including ‘Player A’. But this player is not tagged with ‘Team A’.

    Could you explain me ? Or propose me a solution ?

    Thanks

    https://wordpress.org/plugins/cpt-onomies/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Rachel Carden
    Participant

    @bamadesigner

    When you query the parent of hierarchical terms, it, by default, includes the children terms so querying the parent “Team A” is gonna get all the posts that are assigned to children terms of “Team A”.

    Check out the “include_children” parameter in the Taxonomy section of the WP_Query codex page for more info.

    I’m sorry, I made a mistake in my example.
    It’s exactly the contrary : I query the children term ! (and it returns me its parent)

    array(
       'taxonomy' => 'custom post type',
       'terms' => '2013',
       'field' => 'slug'
    );
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WP_Query with cpt-onomies children terms’ is closed to new replies.