wp-posts-to-posts icon indicating copy to clipboard operation
wp-posts-to-posts copied to clipboard

Getting all connected posts across multiple registered connections

Open nic-bertino opened this issue 13 years ago • 3 comments

Hey all,

I'm looking to create a "stream" of connected information that is time-ordered. I have a custom post_type that I've connected to two other posts with two separate connections. Would it be possible to get both sets of related posts in a single call? If not, any suggestions for merging the two queries?

Thank you,

Nic

nic-bertino avatar Jan 26 '13 19:01 nic-bertino

When you say "two separate connections", do you mean "two separate connection types"?

scribu avatar Jan 27 '13 01:01 scribu

Yes, my apologies!

I'm still getting familiar with the ins and outs of WordPress, but I was able to get what I'm looking for through a SQL statement (hoping not to use this, was mostly to see how the connections work):

SELECT * 
FROM scuwp.wp_posts, scuwp.wp_p2p 
WHERE scuwp.wp_posts.ID = scuwp.wp_p2p.p2p_to and scuwp.wp_p2p.p2p_from = $post_id;

If there's a more elegant way to do this, I'm all ears.

nic-bertino avatar Jan 27 '13 01:01 nic-bertino

You could just pass the connection types as an array:

new WP_Query( array(
  'connected_type' => array( 'C_TYPE_A', 'C_TYPE_B' )
  ...
) );

scribu avatar Jan 27 '13 02:01 scribu