I'm trying to get an individual posts custom taxonomy ID to then print an image with ACF. I've looked at the documentation here on ACF and this support ticket too.
From my understanding it looks like it should work if if I use get_queried_object()
, however I'm not having much luck.
Here is my code:
<?php $producers_assessment_object = get_queried_object();?>
<?php the_field('badge', 'producers_assessment_' . $producers_assessment_object->term_id); ?>
If I manually put in the post ID like so <?php the_field('badge', 'producers_assessment_7'); ?>
the field works as I would like it to.
I've tried using this code below from another SO questions, just to see if I can the term Id in anyway and this also didn't work.
$cate = get_queried_object();
$cateID = $cate->term_id;
echo $cateID;
Here is the code from my functions.php for my custom taxonomy:
register_taxonomy(
'producers_assessment', //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
'producers', //post type name
array(
'hierarchical' => true,
'label' => 'Assessment Stage', //Display name
'query_var' => true,
'rewrite' => array(
'slug' => 'producer-assessment', // This controls the base slug that will display before each term
'with_front' => false // Don't display the category base before
)
)
);
get_the_terms
instead to fetch the terms assigned to each post.term_id
is not a property of the post object. Take a look atget_the_terms()
instead.