Home › Forums › General Issues › 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);
....
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
The topic ‘get_field not working in Categories’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.