Home Forums Front-end Issues Display first level taxonomy automatically


Display first level taxonomy automatically

  • Still learning my way around WordPress and ACF, and I need some help.

    I have a custom taxonomy (location) and an acf single select field (listing_priv_location) for the custom taxonomy.

    Taxonomy is as follows:

    Location A
    — Home
    — Office

    Location B
    — Mall
    — Movie Theatre

    If I select “Movie Theater”, I can get it to display correctly using the following:

    $leveltwo = get_term( get_field( 'listing_priv_location' ), 'location' );
    echo $leveltwo->name;

    Which outputs: Movie Theatre

    How can I display it such that it will automatically add the first level taxonomy:

    Output: Movie Theatre, Location B


  • <?php 
    $leveltwo = get_term( get_field( 'listing_priv_location' ), 'location' );
    echo $leveltwo->name;
    $term = get_term($leveltwo->parent, $leveltwo->taxonomy);
    echo ', ',$term->name;
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Display first level taxonomy automatically’ is closed to new replies.