WordPress.org

Forums

CPT-onomies: Using Custom Post Types as Taxonomies
[resolved] Hierarchical post type (11 posts)

  1. karellm
    Member
    Posted 2 years ago #

    Hi,

    I've created a hierarchical post type and set it as a CPT-onomy with a type of checklist.

    Though, the taxonomy box doesn't consider the hierarchical feature and display them as a list.

    See images:

    http://postimage.org/image/w3c2z39h3/
    http://postimage.org/image/v2bu9yshj/

    Could you implement that? Thanks

    http://wordpress.org/extend/plugins/cpt-onomies/

  2. Rachel Carden
    Member
    Plugin Author

    Posted 2 years ago #

    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.

  3. karellm
    Member
    Posted 2 years ago #

    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?

  4. Rachel Carden
    Member
    Plugin Author

    Posted 2 years ago #

    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.

  5. karellm
    Member
    Posted 2 years ago #

    Ok. Thanks a lot for the great work!

  6. Rachel Carden
    Member
    Plugin Author

    Posted 2 years ago #

    No problem! Glad you like it!

  7. TiagoPires
    Member
    Posted 2 years ago #

    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!

  8. Rachel Carden
    Member
    Plugin Author

    Posted 2 years ago #

  9. Slams
    Member
    Posted 2 years ago #

    Good day,

    I have hierarhical custom post type Ingredients which looks like

    Alcohol
    --Vodka
    --Sambuka
    Eggs
    --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!

  10. Rachel Carden
    Member
    Plugin Author

    Posted 2 years ago #

    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>';
    }
  11. Slams
    Member
    Posted 2 years ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.