WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. kemie
    Member
    Posted 1 year 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:
    http://pastebin.com/dag3wi3b

    Any clues will be appreciated

    http://wordpress.org/extend/plugins/posts-to-posts/

  2. kemie
    Member
    Posted 1 year 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,
    				'cat'=>18,
    			) );
    
    			foreach ( $platinum as $sponsor ) {
    				echo $sponsor->post_title;
    			};
  3. kemie
    Member
    Posted 1 year 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

About this Topic

Tags