I create a field to attach a featured images in the category section, so when you create any category you can add also and images to be display on the frontend.
I need help to show that image I try some code with out luck 🙁
here is the code I use
if(function_exists(“register_field_group”))
{
register_field_group(array (
‘id’ => ‘acf_categories-settings’,
‘title’ => ‘Categories settings’,
‘fields’ => array (
array (
‘key’ => ‘field_55cd9d1bdb108’,
‘label’ => ‘Featured Image’,
‘name’ => ‘categories_featured_image’,
‘type’ => ‘image’,
‘save_format’ => ‘object’,
‘preview_size’ => ‘header’,
‘library’ => ‘all’,
),
),
‘location’ => array (
array (
array (
‘param’ => ‘ef_taxonomy’,
‘operator’ => ‘==’,
‘value’ => ‘category’,
‘order_no’ => 0,
‘group_no’ => 0,
),
),
),
‘options’ => array (
‘position’ => ‘normal’,
‘layout’ => ‘default’,
‘hide_on_screen’ => array (
),
),
‘menu_order’ => 0,
));
}
That’s only the code for registering the field group. In your category template you need to add code to get the field, the exact code will depend on how the image field is set up and how you want to display it. To get the value of the field would be something like this
$queried_object = get_queried_object();
$term_id = $queried_object->term_id;
$image = get_field('categories_featured_image', 'category_'.$term_id);