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

  • 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