Support » Plugin: Posts 2 Posts » Two nested loops- only one works

  • Resolved kemie


    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

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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;

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Two nested loops- only one works’ is closed to new replies.