Home Forums General Issues Retrieving fields for category pages


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.


  • Nevermind, the following worked:

    // 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.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.