Home › Forums › General Issues › Display custom field from category on child single page › Reply To: Display custom field from category on child single page
With a single post page then you need to get the terms associated with the post, get_queried_object() will not help you.
// WP loop
while (have_posts()) {
the_post();
$term = false;
$terms = get_the_terms($post->ID, 'detinations');
// $terms is an array of term object
// use the first term found
if ($terms) {
$term = $terms[0];
if ($term->parent) {
// term is not at the top level
$ancestors = get_ancestors($term_id, 'destinations', 'taxonomy');
$top_term_id = array_pop($ancestors);
$term = get_term($top_term_id, 'destinations');
}
}
// $term now holds the top level term of a hierarchical taxonomy
// based on the first term found for this post
// or false if no term is selected for this post
if ($term) {
// output fields from the term
the_field('big_image', $term);
}
} // end while have_posts
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 use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.