Tagged: custom fields, single, templates
I need to have special fields for some categories in the posts and I am using ACF.
What is the best way to do this and to which template I should add my custom fields code?
A simple example with an if category1, category2, and is single can help to know where and how to add the code.
Thanks.
Hey peterolle,
Thank you for the inquiry.
Where are you displaying the custom fields? Did you modify a template to display them? You should probably add the conditional tags around those modifications. This documentation should help.
// https://developer.wordpress.org/reference/functions/has_category/
Example:
if( has_category("dog"), get_the_ID() ) {
// echo custom field
}
In the code above, the custom field will only display if the post has the category “dog”.
Best regards,
Ismael
Where are you displaying the custom fields? Did you modify a template to display them?
It will be for normal posts under certain categories.
Not implemented yet. Which file should I modify to display them?
Thanks.