WordPress.org

Ready to get started?Download WordPress

Forums

Posts 2 Posts
[resolved] Show only custom post type which has a connection (3 posts)

  1. Michelle
    Member
    Posted 1 year ago #

    Hi & thanks for the great plugin Scribu!

    I'm sure I'm just being dense but I can't get a custom WP_Query to filter out posts that aren't connected via P2P. I have two custom post types, Directory and Projects, and a reciprocal connection between them, directory_to_projects. I want to display a list of all Directory items that have one or more connections to Projects. This is my query:

    $args = array(
                'post_status' => 'publish',
                'post_type' => 'directory',
                'meta_key' => 'faculty_last',
                'orderby' => 'meta_value',
                'order' => 'asc',
                'posts_per_page' => -1,
                'nopaging' => true,
                'suppress_filters' => false,
                'connected_type' => 'directory_to_projects',
                'connected_direction' => 'any',
                'connected_items' => 'any',
            );
     $dir_query = new WP_Query($args);

    When I remove the last three args, the full list of Directory items appears - but with the args in there I get nothing. I should get just one record, as only one of my Directory items is currently connected to any Projects. Any ideas where I'm going wrong? I've read about a billion support posts but I just can't figure it out. Thanks for your help!!!

    http://wordpress.org/extend/plugins/posts-to-posts/

  2. scribu
    Member
    Plugin Author

    Posted 1 year ago #

    I assume the reason you're not getting anything is because you're also passing 'meta_key' => 'faculty_last'. This should work:

    $args = array(
                'post_status' => 'publish',
                'orderby' => 'meta_value',
                'order' => 'asc',
                'posts_per_page' => -1,
                'nopaging' => true,
                'suppress_filters' => false,
                'connected_type' => 'directory_to_projects',
                'connected_direction' => 'from',
                'connected_items' => 'any',
            );
    $dir_query = new WP_Query($args);
  3. Michelle
    Member
    Posted 1 year ago #

    Thank you, that worked! The only thing I had to change was the connected_direction from 'from' to 'to'. You're the best!!!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic