Posts 2 Posts
[resolved] Two nested loops- only one works (3 posts)

  1. kemie
    Posted 2 years ago #

    I'm a bit stumped.
    I have a CPT of event that has another CPT of sponsors connected to it

    On the homepage, I want to show a list of events, and for each event I want to show the sponsors, but first the ones of category "platinum", then "gold" etc.

    So I have multiple nested queries, one for each category ( I know there's probably better ways to do this, but I'm not really a programmer). The problem is only the first one works. The following ones always return

    Warning: Could not find direction(s). in /home/.../wp-content/plugins/posts-to-posts/core/query-post.php on line 16

    regardless of which one is first, only the first one works. I've tried explicitly setting 'connected_direction' => 'any'. this removes the error, but still shows nothing.

    This is my ugly code:

    Any clues will be appreciated


  2. kemie
    Posted 2 years ago #

    Talking to myself here. Not sure what was wrong originally, but solved by instead using foreach:

    $platinum = get_posts( array(
    				'connected_type' => 'sponsors_to_event',
    				'connected_items' => $post,
    				'nopaging' => true,
    			) );
    			foreach ( $platinum as $sponsor ) {
    				echo $sponsor->post_title;
  3. kemie
    Posted 2 years ago #

    Spoke too soon. Now my THIRD loop is not working. I'm tearing my hair out here. Any clues?

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Posts 2 Posts
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic