• Resolved John

    (@jsing)


    I’ve read through the documentation and if I have missed the answer I apologize. What I am trying to do is simply have a page template that displays all the ‘cases’ (CPT) that are connected to the user currently logged in. The connections are there and if I am on the author archive page the widget retrieves the appropriate cases.

    In the instructions it gives this:

    $posts = get_posts( array(
      'connected_type' => 'multiple_authors',
      'connected_items' => $user,
      'suppress_filters' => false,
      'nopaging' => true
    ) );

    I have tried this connection:

    p2p_register_connection_type( array(
    		'name' => 'cases_to_users',
    		'from' => 'cases',
    		'to' => 'user'
    		)
        );

    With this:

    <?php global $current_user;
          get_currentuserinfo();
    
      	$user = $current_user->ID;
    
    $connected = get_posts( array(
      'connected_type' => 'cases_to_users',
      'connected_items' => $user,
      'suppress_filters' => false,
      'nopaging' => true
    ) );
    
    echo $connected;
    
    // Display connected pages
    if ( $connected->have_posts() ) :
    ?>
    <h3>Related Cases:</h3>
    <ul>
    <?php while ( $connected->have_posts() ) : $connected->the_post(); ?>
    	<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endwhile; ?>
    </ul>
    
    <?php
    // Prevent weirdness
    wp_reset_postdata();
    
    endif;
    ?>

    I get this error:

    Fatal error: Call to a member function have_posts() on a non-object

    I think I am just not passing the right thing into $user. Any help would be appreciated.

    https://www.ads-software.com/extend/plugins/posts-to-posts/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author scribu

    (@scribu)

    Just replace get_posts( with new WP_Query(.

    Also, instead of calling get_currentuserinfo(), just use:

    $user = wp_get_current_user();
    Thread Starter John

    (@jsing)

    Thanks for the quick support, this is an awesome plugin.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Display Posts Connected to Current User’ is closed to new replies.