I am currently developing a site, I have three custom post types (speakers, events, videos). Each event has a relationship with speakers so when a event is created they select what speakers spoke at that event. my event page works fine and I can call the speakers fine. The problem I am having in my videos custom post type when creating a video the user has 2 relationships which they select which event it was recorded at and what speaker it is for. So on my events page under each speaker. I want it to get their video for that event. i have tried using meta query’s but I cannot get it to work. I have posted on ACF forum with no reply. Any help would really be appreciated I have tried everything I can think of.
http://support.advancedcustomfields.com/forums/topic/nesting-relationship-querys/
Above is the post on advanced custom field support forum.
Here is a paste bin of my events.php
Here is the section of code ,
<?php
$posts = get_field('speakers');
if( $posts ) :
foreach( $posts as $post) :
setup_postdata($post);
?>
<div class="span_6 speaker">
<div class="span_5">
<img src="<?php the_field('speakers_image'); ?>" />
</div>
<div class="span_7">
<h3><?php the_title();?></h3>
<?php
$videos = get_posts( array(
'post_type' => 'videos',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'speaker',
'value' => get_the_ID()
),
array(
'key' => 'events',
'value' => $eventid
)
)
) );
$videoquerys = new WP_Query($videos);
?>
<a class="" href="#">View Profile</a>
</div>
</div>
Above is what i have tried the information between event and speaker i can get fine its querying the speaker and event and getting the video that matches i am having trouble with.
Looks like you’re using both
get_posts()
andnew WP_Query()
— You only need one or the other. You’re also usingWP_Query()
incorrectly — It’s looking for an array of arguments, but you’re passing$videos
, which is an array of post objects.Try this:
Untested. Hope it works for you.
I got this working after by using the below code
http://hastebin.com/dufucamaja.xml