1

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

http://pastebin.com/LB8bdyKj

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.

2
  • If you really want someone help you, try to isolate the relevant code (i. e. related to your question), and then paste it here instead of on an external site.
    – gmazzap
    Commented Nov 8, 2013 at 16:41
  • Have updated my code
    – user41522
    Commented Nov 8, 2013 at 17:18

2 Answers 2

0

Looks like you're using both get_posts() and new WP_Query() -- You only need one or the other. You're also using WP_Query() incorrectly -- It's looking for an array of arguments, but you're passing $videos, which is an array of post objects.

Try this:

<?php

$args = array(
  'post_type' => 'videos',
  'meta_query' => array(
    'relation' => 'AND',
    array(
     'key' => 'speaker',
     'value' => get_the_ID()
    ),
    array(
     'key' => 'events',
     'value' => $eventid
    )
  )
);

$videos = new WP_Query($args);

if($videos->have_posts()) : 
   while($videos->have_posts()) : 
      $videos->the_post();

?>

<!-- STUFF FOR EACH VIDEO HERE -->
<a href="<?php the_permalink(); ?>" ?>"><?php the_title(); ?></a>

<?php

endwhile;
endif;

?>

Untested. Hope it works for you.

1
-2

I got this working after by using the below code

http://hastebin.com/dufucamaja.xml

1
  • 2
    Please consider including code (or relevant parts from it) inline, since external links are not guaranteed to stay alive in the future.
    – Rarst
    Commented Nov 15, 2013 at 11:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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