Post 2 Post: Getting connected ‘person’ from post author

I am using the amazing P2P plugin (many thanks Scribu!) and I am having an issue that is probably right in front of my face but I just can’t see.

I have a ‘People’ as CPT and I have connected that to ‘Users’ with a ‘Person_to_User’ connection I created.

Read More

On single posts I want to get the connected ‘person’ in my ‘People’ CPT from that post author.

It seems like that should be fairly simple to do but my brain is hurting from trying to get this and I can’t spend much more time on this.

Related posts

1 comment

  1. On single post, try something like this:

    $author_id = get_the_author_meta('ID');
    
    $people = get_posts( array(
      'connected_type' => 'people_to_user', // replace with whatever
      'connected_items' => $author_id,
      'suppress_filters' => false,
      'nopaging' => true
    ) );
    

    Now $people[0] references the first (and only) author related to the post you’re on. So $people[0]->ID can be used to get the various bits of content, thumbnail, custom meta, etc.

Comments are closed.