Ready to get started?Download WordPress


Display/show/list custom terms in heirarchy order - not alphanumerical (11 posts)

  1. Pete
    Posted 10 months ago #

    Can anyone be able to tell me....

    1. why these 3 pieces of code DON'T display/list show my custom hierarchial terms in hierarchy order?
    2. how I can make them display/show/list in hierarchial order

    All 3 do basically the same thing but they all in alphanumercial order rather hierarchy order.

    Thanks heaps, Pete


    <?php echo '<ul class="styles">';
    echo get_the_term_list( $post->ID, 'program', '<li>', ',</li><li>', '</li>' );
    echo '</ul>'; ?>

    <?php echo get_the_term_list( $post->ID, 'program', 'Program: ', ', ', '' ); ?>

    <?php the_terms( $post->ID, 'program', 'Program: ', ' / ' ); ?>

  2. keesiemeijer
    Posted 9 months ago #

  3. Pete
    Posted 9 months ago #

    I've already tried that with no luck

  4. keesiemeijer
    Posted 9 months ago #

    Does it display exactly as your first three examples? Silly question, but are both parent and child categories (direct descendants) assigned to the posts you are testing this with?

  5. Pete
    Posted 9 months ago #

    OK I have 5 code examples here...

    This is the screen shot of the 5 codes...

    This is the 5 custom terms (with hierarchy) the post has...

    parent: Towards Independence
    child: 013. Out in the community
    sub-child: A. Going out for a drink
    sub-sub-child#1: 1. Choose a place to go for a drink
    sub-sub-child#2: 2. Choose someone to go with or decode to go on your own

    As you can see...

    111 = no result
    222 = displayed ALL terms with hierarchy (not just the post's terms)
    333, 444, 555 = displayed the correct terms just not in hierarchy order :(

  6. Pete
    Posted 9 months ago #

    The taxonomy name is "program"

  7. Pete
    Posted 9 months ago #

    example 222 displays all the terms even if the post doesn't have ANY assigned to it... 222 essentially displays all the terms assigned to all posts

  8. keesiemeijer
    Posted 9 months ago #

    Are you using this inside the loop? For testing, can you change this:

    $post_terms = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );

    to this:

    $post_terms = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
    echo '<pre>';
    echo '</pre>';
  9. sydcode
    Posted 9 months ago #

    G'day Pete, hope this helps.

    1. Style argument is set to "none", remove to show list.
    'title_li=&echo=0&taxonomy=' . $taxonomy . '&include=' . $term_ids

    2. Need to restrict terms like in #1.

    3. get_the_term_list() can't indent because it just gets the links and builds a string.
    see wp-includes/category-template.php (line 1090)

    4. the_terms() is a wrapper for get_the_term_list(). same as #3.

    5. same as #3.

    Also, you may need to tweak the stylesheet because some themes don't indent lists.

  10. Pete
    Posted 9 months ago #

    Thanks for that guys... OK I think i've sussed most of it out... I'm using the Genesis framework with the simple hooks plugin, something in this isn't allowing code#1 to display, however I tried a 'normal' theme and code #1 works fine , EXCEPT it doesn't show the parent term. Code #1 lo0ks the best so far. Any way to get the parent term to display?

  11. Pete
    Posted 9 months ago #

    Disregard the "Any way to get the parent term to display?" comment... i forgot to check it :P

    Thanks for all your help with this... much appreciated


You must log in to post.

About this Topic