scenerio: I have several events in a CPT called events. For single events, they use template single-event.php. I also have guest speakers, in which each one has post in a CPT called speakers.

I'd like to create a query that pulls a custom field from a speaker post with a key's value that matches the event title.

The idea is to display a subset of my speakers on a specific event based on the meta value of the speaker post using a single event template page.

  • site is at tlh.villagesquare.us – user100754 Aug 10 '16 at 19:12

It's pretty easy actually in your single-event.php file within the content loop. add this loop where you want your speakers information to show.

$event_title = get_the_title(); // This is the title of the current single event page we are on.
$args = array(
  'meta_key'        => 'event_name', // the name of your custom field
  'meta_value'      => $event_title,
  'post_type'       => 'speakers',


$speakers_query = new WP_Query( $args );

if( $speakers_query->have_posts() ) :

  echo '<ul>'; // start your section here

  while( $speakers_query->have_posts() ) : $speakers_query->the_post();

    // echo your speaker content here like name, images, etc.
    echo '<li>' . get_the_title() . '</li>';


  echo '</ul>'; // end your section here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.