Support

Account

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
    }