WordPress.org

Support

Support » How-To and Troubleshooting » Display/show/list custom terms in heirarchy order – not alphanumerical

Display/show/list custom terms in heirarchy order – not alphanumerical

  • 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

    #1

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

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

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

Viewing 10 replies - 1 through 10 (of 10 total)
  • Moderator keesiemeijer

    @keesiemeijer

    I’ve already tried that with no luck

    Moderator keesiemeijer

    @keesiemeijer

    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?

    OK I have 5 code examples here…
    http://pastebin.com/VsFfRVRS

    This is the screen shot of the 5 codes…
    http://snag.gy/Q9JVW.jpg

    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 🙁

    The taxonomy name is “program”

    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

    Moderator keesiemeijer

    @keesiemeijer

    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>';
    print_r($post_terms);
    echo '</pre>';

    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.

    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?

    Disregard the “Any way to get the parent term to display?” comment… i forgot to check it 😛

    Thanks for all your help with this… much appreciated

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Display/show/list custom terms in heirarchy order – not alphanumerical’ is closed to new replies.
Skip to toolbar