Support

Account

Home Forums General Issues get_field not working in Categories

Solving

get_field not working in Categories

  • 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!
    m

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

    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. https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/

    Do you have the image field set to return a URL? https://www.advancedcustomfields.com/resources/image/

  • 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)

The topic ‘get_field not working in Categories’ is closed to new replies.