4

I'm asking regarding the ACF plugin (Advanced Custom Fields)

I'm working on creating a category group that will add custom fields to the category pages. These are the fields:

enter image description here

They seem to work in storing the data (I can see the data is saved with an example category)

enter image description here

According to the docs, I'm supposed to use get_field in the template files to get the value of the custom field. I'm in the category.php template, and using get_field returns FALSE (bool).

Here is my code:

$sub_heading = get_field("sub_heading");

That should get the text that's stored in the "sub_heading" custom field, but instead it just returns FALSE (bool).

I also tried

$sub_heading = get_field("sub_heading", $cat->term_id)

The category page is displaying the category properly, and giving me the title and the description, but nothing is being returned from get_field.

1 Answer 1

5

Nevermind, I figured this out.

The id needs to be "category_" and then the ID.

So the code is:

$sub_heading = get_field("sub_heading", "category_" . $cat->term_id);
1
  • can you mark this question answered?
    – jgraup
    Commented Dec 24, 2015 at 17:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.