Support

Account

Home Forums Front-end Issues Taxonomy Name in Archive Page Not Working

Solved

Taxonomy Name in Archive Page Not Working

  • Hello.
    I have created a custom field.
    Field Type = Multi Select Taxonomy
    Field Name = cat_related_tags
    Taxonomy = post_tag

    <?php 
    $terms = get_field('cat_related_tags', $queried_object); 
    if( $terms ):
    foreach( $terms as $term ):  
    
    echo $term;
    echo get_term_link($term);
    echo $term->name; /*Not Working */
    
    endforeach;
    endif; 
    ?>

    Here, $terms shows me the id. It is correct.
    get_term_link shows me the url of tag. It is correct also.
    But I couldn’t get the tag name or other information. What is wrong with this, what should I do? Thank you.

  • From the looks of things you are only returning the term ID, it’s one of the settings for a taxonomy field. To get the other information you need to set the return value to Term Object. This may alter how you call some of the other functions because you’ll get the entire object rather than just the ID

  • Thank you. I am looking for the “return value to Term object” in Google, but I couldn’t understand the operation logic of php codes. May I ask you to help me with the codes, please? Maybe just a little code, but I couldn’t do it.
    Thank you.

  • There is a setting in the ACF admin where you edit the field that sets the return value, no coding required for that part.

  • Yes, thank you for your help. I have solved it. When you do Term Object instead of Term ID, it will work. And the code is for example here.

    <?php 
    $terms = get_field('cat_related_tags', $queried_object); 
    if( $terms ):
    foreach( $terms as $term ):  
    $cat_image = get_field('cat_image', $term ); ?>
    endforeach; 
    endif; 
    ?>

    I have one more question. I am on tag.php and I am trying to get Custom Field Image. This code didn’t work here. Did I do something wrong? Thank you.

    <?php $cat_image = get_field('cat_image'); ?>
    <?php the_field('cat_image'); ?>
  • I did this also, here is the code.

    
    <?php $term = $wp_query->queried_object; ?>
    <?php the_field('cat_image', $term); ?>
    

    Thank you for your help.

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

The topic ‘Taxonomy Name in Archive Page Not Working’ is closed to new replies.