I have a image field added to the Posts Category taxonomy and it’s working great within the category.php template page.
However I do have a function called on other pages which I’d like to reference the same image field.
I can’t seem to pull the field due to requiring additional details to call from another page but I can’t seem to get it working.
I’ve seen many suggest
the_field('image', 'category_' . $post->ID);
or
$queried_object = get_queried_object();
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;
the_field('image', $post->ID);
Sadly neither of these are working from the functions.php function.
The end goal would be to have an if statement checking if that field exists and returning a response if it does.
function imageFound($atts){
if(get_field('image', $post->ID))
{
the_field('image', $post->ID);
} else {
echo 'Sorry, the image:'. $atts . ' was not found.';
}
}
I’d make more use of $atts but I’m just simplifying it for this example.
I’m appreciative of any input regarding this.