Support

Account

Home Forums General Issues How to get custom field from custom taxonomy

Solved

How to get custom field from custom taxonomy

  • I am trying to retrieve a field from a custom taxonomy so that each post will have a featured image however, i cannot seem to get the field when using the field name and ID. For example,

    `foreach ($terms as $term) {
    echo $term_id;
    echo ‘<li><a href=”‘.get_term_link($term).'”>’.$term->name.'</a></li>’;
    echo get_field(‘workspace_featured_image’, “workspace_category_12”);
    echo get_field(‘workspace_featured_image’, $term->taxonomy . ‘_’ . $term->term_taxonomy_id);
    echo $term->taxonomy . ‘_’ . $term->term_taxonomy_id;

    }`

    When i run the bottom line it displays “workspace_category_number” which i believe is correct however, it is still not displaying when i use it with get_field().

    Any help would be much appreciated.

  • you should be able to use

    
    echo get_field('workspace_featured_image', $term);
    

    you can also use

    
    echo get_field('workspace_featured_image', 'term_'.$term->term_id);
    

    or even

    
    echo get_field('workspace_featured_image', $term->taxonomy.'_'.$term->term_id);
    

    This is all covered in the guide: Adding fields to a taxonomy term .

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

You must be logged in to reply to this topic.