Support

Account

Home Forums General Issues Display Taxonomy Hierarchy

Solving

Display Taxonomy Hierarchy

  • I’m trying to display the taxonomy hierarchy as such: ‘child’ – ‘parent’

    I followed the instructions here: https://www.advancedcustomfields.com/resources/taxonomy/

    but this method does not display the hierarchy.

    Any ideas?

  • Iā€™m trying to display the Hierarchical custom Fields

    https://support.advancedcustomfields.com/forums/topic/hierarchical-custom-fields/

    but this method does have solutions šŸ™ .

    Like:

    custom field A
    ā€“ custom field A1
    ā€” custom field A1.1
    ā€” custom field A1.2
    ā€” custom field A1.2.1
    custom field B
    ā€“ custom field B1
    ā€” custom field B1.1
    ā€” custom field B1.1.1

    Any ideas?

  • How to show a hierarchical terms list?

  • There is not enough information in any of the comments to tell what anyone is attempting to do?

    What kind of field are you using? What code are you using? More detail on what you are trying to do and where you are trying to do it? What is not working?

  • Sure, here’s a direct idea that you can use to display the taxonomy hierarchy on your WordPress website:

    You can use the get_ancestors() function in WordPress to retrieve the ancestors of a taxonomy term. This function returns an array of term IDs, which you can then use to display the hierarchy.

    Here’s an example code snippet that you can use:

    <?php
    // Get the current taxonomy term
    $term = get_queried_object();

    // Get the ancestors of the current term
    $ancestors = get_ancestors( $term->term_id, $term->taxonomy );

    // If there are ancestors, display them
    if ( $ancestors ) {
    // Reverse the order of ancestors to display them from parent to child
    $ancestors = array_reverse( $ancestors );

    // Loop through the ancestors and display them
    for each ( $ancestors as $ancestor ) {
    $ancestor_term = get_term( $ancestor, $term->taxonomy );
    echo esc_html( $ancestor_term->name ) . ‘ – ‘;
    }
    }

    // Display the current term
    echo esc_html( $term->name );
    ?>
    This code will retrieve the ancestors of the current taxonomy term and display them with the current term, separated by a dash. You can modify the output as per your requirements.

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘Display Taxonomy Hierarchy’ is closed to new replies.