Created
November 20, 2016 06:38
-
-
Save ammist/f562e3574457d906b82019db41303ab7 to your computer and use it in GitHub Desktop.
WordPress Posts, Postmeta, Posts 2 Posts Queries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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' ); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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