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

Allow querying multiple connection types

Open scribu opened this issue 14 years ago • 2 comments

Example:

$query = new WP_Query( array(
  'connected_items' => get_queried_object_id(),
  'connected_type'  => array( 'person_to_interview', 'video_to_person' ),
) );

The SQL is easy:

WHERE (p2p_type = 'person_to_interview' AND p2p_from = 123)
OR          (p2p_type = 'video_to_person' AND p2p_to = 123)

Requested in #119 and http://wordpress.org/support/topic/plugin-posts-2-posts-get-all-connections-at-once

scribu avatar Feb 23 '12 21:02 scribu

Fantastic, looking forward to it :)

PorridgeBear avatar Feb 23 '12 21:02 PorridgeBear

Hello,

I am using this to get connected posts from two connections as given below:

$connected = new WP_Query( array(
    'connected_type' => array( 'artists_to_posts', 'artists_to_competitions' ),
    'connected_items' => get_queried_object_id(),
) );

But the problem is that this query is not returning the connected posts from second connections. I have looked at the SQL and found the following:

AND wp_posts.post_type = 'post'

The SQL works if I changed it to the following:

AND ( wp_posts.post_type = 'post' OR wp_posts.post_type = 'competition' )

Please help.

UPDATE:

This is now working. I have changed the query as follow:

$connected = new WP_Query( array(
    'connected_type' => array( 'artists_to_posts', 'artists_to_competitions' ),
    'connected_items' => get_queried_object_id(),    
    'post_type' => array( 'post', 'competition' ),
) );

iammahmudur avatar Jul 01 '13 06:07 iammahmudur