Support

Account

Home Forums General Issues Show Custom Field results from one post type in template of another Reply To: Show Custom Field results from one post type in template of another

  • Here’s a step-by-step.
    1. Find a way to get the artist’s name. It’s stored as the post’s title. Great. We can grab it with the_title().
    2. Find where the artist is declared in the ‘release’ CPT. It’s inside a custom field named album_artist. Custom fields are stored inside meta keys.
    3. Construct a query with these values and spit out the results. You get:

    <?php
    $args = array(
      'numberposts'=> -1,           // Fetch all posts...
      'post_type'=> 'release',      // from the 'release' CPT...
      'meta_key' => 'album_artist', // which inside this meta key...
      'meta_value' => the_title()   // has this meta value.
    );
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) :
      echo '<ul>';
      while ($my_query->have_posts()) : $my_query->the_post();
    ?>
    
    <li><?php the_field('album_title') ?></li>
    
    <?php 
    endwhile; echo '</ul>';
    endif; wp_reset_query(); ?>

    Hope that helped.