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

Is there a method to get posts that have at least one connection of a given connection type? #461

Open
l3rady opened this issue Oct 2, 2014 · 1 comment

Comments

@l3rady
Copy link

l3rady commented Oct 2, 2014

I'm looking to query a post type but I dont want to return posts that don't have a connection to another post.

Is it possible?

@davidchoy
Copy link

Scribu suggested the answer is "no" two years ago: https://wordpress.org/support/topic/connected_to-any-returning-duplicates

And suggests re-indexing by id to remove duplicates.

I feel there is, or there should be, a better way to do this. Right now, I'm doing this with get_posts like this (kinda ugly):

//get all instructors that have course connections
$instructors = get_posts( array(
'supress_filters' => false,
'post_type' => 'person',
'posts_per_page'=>-1,
'connected_type'=>'course_to_instructor',
'connected_direction'=>'from',
'connected_items'=>'any',
'orderby'=>'title',
'order'=>ASC,
) );
//remove duplicates
$instructors = array_reduce($instructors, function($acc, $curr){
$acc[$curr->ID] = $curr;
return $acc;
}, array());

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

2 participants