Home › Forums › General Issues › Display custom field from category on child single page › Reply To: Display custom field from category on child single page
I’m not sure what you mean, your title says “child single page” which leads me to believe you want to do this on a single post page… but your then you say that you want to get the image from the parent category.
If you are on a single post, the first thing you need to do is get the terms for the post. https://developer.wordpress.org/reference/functions/get_the_terms/
Once you have the terms and you want to get the top level term
$top_term = $term;
if ($term->parent) {
// term has a parent
$ancestors = get_ancestors($term_id, 'your-taxonomy-name-here', 'taxonomy');
$top_term_id = array_pop($ancestors);
$top_term = get_term($top_term_id, 'your-taxonomy-name-here');
}
if(get_field('big_image', $top_term)) {
/// your code here
}
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.