Ok, I understand.
It says :
Uncaught Error: Cannot use object of type WP_Error as array in /Users/Path/single-destinations.php:15
Line 15 is :
$term = $terms[0];
Does it help ?
Thank you John,
You code gives me blank page (I saw and correct the forgotten “s” in the first “destinations” term).
I don’t know where is the problem.
The big_image is defined in the “swimming” category from the “destinations” custom post type/taxonomy.
Maybe I was not clear enough on the point ?
Sorry I’m really not good at php … 🙁
Hello John,
Thank you for your help.
Indeed, I’m talking about a single post page.
Do I need to specify that it’s a category from a custom post type ?
So it’s a taxonomy called “destinations”.
So I adapt your code like this in my template single-destinations.php, no ? :
<?php $top_term = $term;
if ($term->parent) {
// term has a parent
$ancestors = get_ancestors($term_id, 'destinations', 'taxonomy');
$top_term_id = array_pop($ancestors);
$top_term = get_term($top_term_id, 'destinations');
}
if(get_field('big_image', $top_term)) { ?>
<p>Hello !</p>
<?php } ?>
Nothing happens… 🙁 Is there something wrong ?
C’est parfait merci beaucoup ! 🙂
Hello,
I’m trying to do the same thing, but ONLY for the current parent category.
Here the code displays all the elements for ALL categories.
Do you know what do I have to adapt ?
Thanks in advance for your help.