Skip to content

Instantly share code, notes, and snippets.

@ammist
Created November 20, 2016 06:38
Show Gist options
  • Save ammist/f562e3574457d906b82019db41303ab7 to your computer and use it in GitHub Desktop.
Save ammist/f562e3574457d906b82019db41303ab7 to your computer and use it in GitHub Desktop.
WordPress Posts, Postmeta, Posts 2 Posts Queries
/*
* Get the events for each person
*/
$events = new WP_Query(
array (
'post_type' => 'event',
'connected_type' => 'speaker_to_event',
'connected_items' => $speaker->ID,
)
);
/*
* Get the speakers (a type of person) for each event
*/
$event_speakers = new WP_Query(
array (
'post_type' => 'person',
'connected_type' => 'speaker_to_event',
'connected_items' => $event->ID,
)
);
/*
* Takes an input array of events and attaches all of the speakers connected to each one
*/
p2p_type( 'speaker_to_event' )->each_connected(
$events_list, array(), 'person' );
-- Select posts by postmeta, with Advanced Custom Fields(ACF) metadata
-- In this scenario a use ha
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment