0

Hi can anyone please help me,

I want to display child taxonomy first before the parent.

Example: Street Name is the child, City Name is the parent

to make it more formal, i want to display Street Name first before City Name. like: Downtown street, Dubai

Thanks in Advance.

0

My assumption here is that within your data structure you have only two level hierarchy:

  1. Countries are always top level parent terms (they never have their own parents),
  2. Streets are first level children, and each street only has one parent and no children.

Do you need a list of all terms? In that case you could output all Streets by picking terms that do not have children, then loop through them to show their parents:

    <?php
    $terms = get_terms( [
       'taxonomy'   => 'your-taxonomy-name',
       'hide_empty' => false,
       'childless'  => true, // this will make sure we pick only terms that have no children, so no countries, only streets
    ] );
    ?> 

    <ul>
        <?php
        foreach( $terms as $street ) {
            $country = get_term( $street->parent, 'your-taxonomy-name' );

            if ( ! is_wp_error( $country ) ) {
                echo sprintf( '<li>%1$s, %2$s</li>', $street->name, $country->name );
            }
        }
        ?>
    <ul>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.