Home › Forums › General Issues › get_field doesn’t work for tags
I have created a field group which is set to be visible for Taxonomy if it’s equal to Tag (post_tag). I can see the field with it’s default value when editing tag but I can’t get that value in my code. I always get it returned as null.
How I’m trying this field value:
$term = get_queried_object();
$field_value = get_field('tag_', $term->term_id, 'about_schema');
I tried var_dump($term) and it returns me this:
object(WP_Term)#8411 (10) { ["term_id"]=> int(7346) ["name"]=> string(13) "Hedera (HBAR)" ["slug"]=> string(11) "hedera-hbar" ["term_group"]=> int(0) ["term_taxonomy_id"]=> int(7346) ["taxonomy"]=> string(8) "post_tag" ["description"]=> string(0) "" ["parent"]=> int(0) ["count"]=> int(12) ["filter"]=> string(3) "raw" }
In this var_dump I can’t see the values added from ACF field.
What I’m doing wrong here?
$field_value = get_field('tag_', $term->term_id, 'about_schema');
Argument 1: $field name = “tag_”: is this the field name?
Argument 2: $post_id: In this case use either $term
or 'term_'.$term->term_id
Argument 3: $format: should be true or false, any non empty value will evaluate to true.
Name of the field is about_schema
.
So you are saying that those two lines should look like this?
$term = get_queried_object();
$field_value = get_field('about_schema', $term, true);
I tested it but the result is still null.
Third argument is optional, default value is true, but yes.
If get_queried_object() is returning a term and the term returned has a value for the field “about_schema” then there is no reason it should not be working.
Is your field nested in a repeater, or group field?
Double check your field name. Double check that the field has a value.
Check to make sure your field name is not colliding with something else, another input field either in ACF or another plugin that might be adding fields to terms.
My field is a group field. I created the new unique name that it couldn’t match any other name. I copied that fields name to my code. For that field I set the default value. Still nothing.
A group field has sub fields. Is about_schema
the group field name or is that one of the sub fields?
… looking back at OP, you said
In this var_dump I can’t see the values added from ACF field.
values for ACF fields are not added to the Term object.
$field_value = get_field('about_schema', $term, true);
The value of the field will be in $field_value
Here’s the photo of the inside of that field group.
A “Field Group” and a “Group Field” are different things. A field group holds all the fields. A group field is a type of field that is used for display purposes to group a set of sub fields together.
If the fiels has a value then there is not reason that it should not be working
$field_value = get_field('about_schema', $term, true);
echo $field_value;
I don’t know what happened here but it works now. Out of nowhere. I just copied your line for some reason, refreshed the website and it’s finally here. Thank you for your time!
You must be logged in to reply to this topic.
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.