WordPress.org

Ready to get started?Download WordPress

Forums

CPT-onomies: Using Custom Post Types as Taxonomies
WP_Query with cpt-onomies children terms (3 posts)

  1. JudeAAZ
    Member
    Posted 6 months ago #

    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/

  2. Rachel Carden
    Member
    Plugin Author

    Posted 6 months ago #

    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.

  3. JudeAAZ
    Member
    Posted 6 months ago #

    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'
    );

Reply

You must log in to post.

About this Plugin

About this Topic