Support

Account

Home Forums General Issues Retrieving fields for category pages

Solved

Retrieving fields for category pages

  • Hi,

    So I have a background-image field which takes an image for my posts/pages and category pages. I got the field to work for all three but it’s not returning a value for my category pages.

    I’ve read the documentation, and I’ve come up with this:

    <?php global $post;
    $terms = get_the_terms($post->ID, 'category');
    $image = get_field('background_image', 'category_' . $term->term_id ); ?> 

    It doesn’t work. I need this to be on the header so if background_image exists, it knows to grab that url and apply a background image.

    Thanks

  • Nevermind, the following worked:

    <?php 
     
    // vars
    $queried_object = get_queried_object(); 
    $taxonomy = $queried_object->taxonomy;
    $term_id = $queried_object->term_id;  
     
    // load thumbnail for this taxonomy term
    $thumbnail = get_field('background_image', $taxonomy . '_' . $term_id);
     echo $thumbnail;
    ?>
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Retrieving fields for category pages’ is closed to new replies.