Home › Forums › General Issues › Using ACF in Theme
Hey guys! I’ve been having a LOT of trouble trying to use ACF in my theme. What I’m trying to do is use the fields on category pages. Each category is the name of a company and I want different fields about the company such as when it was founded, how big it is, etc. The layout I want is below:
Founder(s): John Smith
Could anyone help me with the code I need to use?
Sounds like this guide will help you out:
Thanks Elliot. So I managed to display the field on one of my category pages. But how can I make it so that the information is displayed on all of my pages and will change depending on the page? Also is there a way to display the field name as well?
Thanks, and sorry for being a total noobie about this!
What do you mean by ‘displayed on all of my pages’?
On every template? Like in the footer?
Maybe you need to fully explain the brief
To get the field label, you will need to load the field object with the get_field_object function (please read the docs for this) to load the field.
Sorry that was very vague of me. What I meant is that I want it displayed on all of my category pages. In other words, is there a code to display the field where I don’t have to use a particular category ID, but instead it uses the ID of whatever page is being loaded?
Thanks, and let me know if i’m still being too vague…
Let me rephrase what I want, just to be clear. I want to display custom fields on my category pages. I also want to display the field label, but ONLY when there is a value to be displayed after it, as that will not always be the case. The layout I want is displayed below:
Founder(s): Jim Smith, John Bob
I DO NOT want field labels to be displayed if I have not entered a value for the field, as will often be the case.
Thanks so much for your help!
Did you look at the last code example on the linked documentation article?
That example shows how to dynamically find the term_id and taxonomy.
All you need to do is swap get_field to get_field_object
The topic ‘Using ACF in Theme’ 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’re hard at work on ACF 6.1, and Beta 1 is now available 🚀— Advanced Custom Fields (@wp_acf) March 16, 2023
This release includes custom post type and taxonomy registration, an improved experience when selecting field types, PHP 8.1 and 8.2 compatibility, and more!
Let’s take a look 🧵https://t.co/Y0WcAT11l4
© 2023 Advanced Custom Fields.