• Resolved Matt Sartori

    (@msartori)


    Hi,

    This code is returning data just fine:

    $connected = new WP_Query( array(
      'connected_type' => 'projects_to_projects',
      'connected_items' => get_queried_object(),
      'nopaging' => true
    ) );

    When I try to loop and print the results, nothing is echoed to the screen. The following code does not seem to print anything.

    // Display connected pages
    if ( $connected->have_posts() ) {
    
    	echo '<ul class="group">';
    		while ( $connected->have_posts() ) : $connected->the_post();
    			echo '<h3 class="project-title">' . $post->post_title . '</h3>';
    		endwhile;
    	echo '</ul>';
    
    	// Prevent weirdness
    	wp_reset_postdata();
    
    }

    ( if ( $connected->have_posts() ) ) looks like it returns false so nothing happens inside of that if/then. Could it be a problem that $connected is returning an object with yet another object inside that contains the actual post data?

    Here’s a pastebin link to the code I’m using.

    This is the actual output from the site.

    Thanks!

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

Viewing 1 replies (of 1 total)
  • Thread Starter Matt Sartori

    (@msartori)

    Just for posterity’s sake I wanted to say there’s nothing wrong with the plugin or the code I posted. I just misunderstood how reciprocal connections work.

Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: Posts 2 Posts] $connected not working in loop’ is closed to new replies.