[Resolved] Hierarchical post type

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


    Actually, it’s working the way it’s supposed to. When a post that has children is selected, or if a child post is selected, it separates the post from its “relatives”. If you unselect “Panama”, “Panama 2012” should show up as its child.

    Thanks for the quick answer!

    It indeed works. My bad.

    I understand why it separates it but visually it would make more sense that they remain nested even if unchecked. It is not because Panama is checked that all is children should be.

    Do you know why it is handled that way?

    Plugin Author Rachel Carden


    I don’t know why, sorry. It’s just how WordPress decided it should be.

    And, because I try to keep CPT-onomy functionality as close to taxonomy functionality as possible, I use the same function they use – wp_terms_checklist() – to print the CPT-onomy checklist so it’s going to work the same as a taxonomy checklist.

    Ok. Thanks a lot for the great work!

    Plugin Author Rachel Carden


    No problem! Glad you like it!

    Having CPT “Packages” associated to CPT “Cities” being both flat no hierarchical post types.

    I was trying to, under “Package” edit screen, make Cities metabox display as checkboxes (like categories as opposed to tags) so user can see a set list of cities layed out. It’s like display a list of tags with checkboxes and not as an smart input field.

    Do you know of a filter or funciton for that with CPTonomy?

    Thanks a lot for your time Rachel!

    Plugin Author Rachel Carden


    Good day,

    I have hierarhical custom post type Ingredients which looks like

    –Chicken eggs
    –Crocodile eggs

    and so on.

    Ingrediens is marked up like taxonomy for cpt Recipe.

    I’m trying to get list of

    $ingredients_by_parent = get_terms( 'ingredients','orderby=name&parent=12229&hide_empty=0' );
                   foreach ($ingredients_by_parent as $ingredient)
                       echo '<li><a href="#" rel="'.$ingredient->term_id.'">'.$ingredient->name.'</a></li>';

    parent=12229 – Alcohol ID

    But I get all list of ingredients with parents. When I set hide_empty to 1, I get just 2 ingredient.

    This code worked fine when ingredients was as custom type taxonomy, but, because of I need to add several meta-boxes to ingredients I have to register ingredienta as custom post.

    Thank you for your great plugin and thank you in advance for help!

    Plugin Author Rachel Carden


    Your problem is you’re using the wrong function. get_terms() just retrieves terms from a particular taxonomy/CPT-onomy. It does not retrieve the terms from a particular taxonomy/CPT-onomy who are associated with a post.

    You need get_the_terms() where the $post_id is the ID for alcohol (12229) and the $cpt_onomy is ‘ingredients’:

    $ingredients = get_the_terms( 12229, 'ingredients' );
    foreach ( $ingredients as $ingredient ) {
       echo '<li><a href="#" rel="'.$ingredient->term_id.'">'.$ingredient->name.'</a></li>';

    Thank you for explanation Rachel!

    I’ve rewrote this code using get_posts and get_post function. Everything work well but now it’s interesting which function is better for performance or it does not matter?

    I call this list of ingredients function by ajax and also use custom fields for each ingredient post.

    Thank you in advance again!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘[Resolved] Hierarchical post type’ is closed to new replies.
Skip to toolbar