Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query vars failing to find connected posts #438

Open
philipjohn opened this issue May 2, 2014 · 0 comments
Open

Query vars failing to find connected posts #438

philipjohn opened this issue May 2, 2014 · 0 comments

Comments

@philipjohn
Copy link

In attempting a custom Query using P2P's query vars I'm struggling to get anything back that makes sense.

My end goal is a list of videos that are connected to a single event.

My connection:

p2p_register_connection_type( array(
    'name'        => 'event_videos',
    'from'        => 'video',
    'to'          => 'event',
    'cardinality' => 'many-to-one',
    'sortable'    => 'any',
) );

I have an event (58059) connected to a single video (61427). I am attempting to retrieve all videos connected to the event 58059. I'm using this code to test the query:

require_once 'wp-load.php';

$q = new WP_Query( array(
    'connected_items' => 58059,
    'connected_type' => 'event_videos',
    'post_type' => 'any',
) );

if ( $q->have_posts() ) {

echo '<ul>';

    while ( $q->have_posts() ) {

        $q->the_post();

        echo '<li>' . get_post_type( get_the_ID() ) . ': ' . get_the_ID() . '</li>';

    }

    echo '</ul>';

}

else {
    echo 'No posts.';
}

This results in No posts. which is unexpected. I expect a list with one item - the ID of my single linked video 61427.

I've tried these variations for query args;

'connected_items' => 58059,
'connected_direction' => 'from',
'connected_type' => 'event_videos',
'post_type' => 'any',

...and changing connected_direction to "to" and "any" produces the same result.

'connected_direction' => 'from',
'connected_type' => 'event_videos',
'post_type' => 'any',

The above produces a list of events, but changing 'connected_direction' to 'to' produces no results, which makes me think there is something wrong with one side of the connection.

Edit: Worth nothing is that when I hook pre_get_posts and dump the query there are three queries performed; the first with post_type set to all, the second set to 'video' and the third to 'event'. That second query includes 'post__in' with 58059 as the value, which clearly isn't going to work. You can see that on pastebin.

@philipjohn philipjohn changed the title Query vars failing to find return posts Query vars failing to find connected posts May 2, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant