Home Forums General Issues get_field not working in Categories


get_field not working in Categories

    • matam

    • March 24, 2018 at 11:04 pm

    Hello everyone,

    i have added an image field to customize categories but i cannot seem to be able to retrieve the image url.

    the page is NOT in a loop nor a category.php page but in a generic one.

    this is part of the code:

    $categories = get_categories( $args );
    foreach($categories as $category) { 
    $term = $category->slug;
    echo $term; //correctly displayed
    $img = get_field('immagine_attivita', '$term'); 
    <div class='bgs' data-depth='0.4' style='background: url($img)'></div>
    //this outputs just a partial URL

    tried to do a lot of resaserches, but with no success.

    any hints?

    ty vm!

    $categories = get_categories( $args );
    foreach($categories as $category) { 
    $term = $category->term_id;
    echo $term; //correctly displayed
    $img = get_field('immagine_attivita', 'term_'.$term); 
    • matam

    • March 25, 2018 at 1:35 am


    thank you, but nope, it’s not working 🙁

  • If there is an error then it has to do with something else. This is the correct way to get field values from a term. You can also supply the term object.

    Do you have the image field set to return a URL?

    • matam

    • March 26, 2018 at 12:10 am

    yes i suppose something is not working 😀

    i am attaching the ACF setup (which is correct, according to the same guide you linked, already spotted in the past)

    in the category section i correctly display the image filed but also have a clone in the main area: maybe something fails due to that?

  • i have the same issue.

    i am using get field for category but not working

    get_field('some_field', 'category_categoryID')

    simply not working.

    i have changed that category is not the category for standard posttype but for custom posttype. maybe thats the reason?

  • found a solution.
    had to update (resave) each category term in the backend and now its working.

    greetings Timmi

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

You must be logged in to reply to this topic.

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.