Plugin Author
scribu
(@scribu)
You can do it in two steps:
1. Get all the IDs of the issues categorized ‘current’:
$issue_ids = get_posts( array(
'fields' => 'ids',
'post_type' => 'issue',
'category_name' => 'current',
'nopaging' => true
) );
2. Get the articles connected to those issues:
$articles = new WP_Query( array(
'connected_type' => 'YOUR_CONNECTION_TYPE',
'connected_items' => $issue_ids,
'orderby' => 'rand',
'posts_per_page' => 1
) );
Plugin Author
scribu
(@scribu)
Maybe something like this would be nice to have:
$articles = new WP_Query( array(
'connected_type' => 'YOUR_CONNECTION_TYPE',
'connected_query' => array(
'category_name' => 'current',
),
'orderby' => 'rand',
'posts_per_page' => 1
) );
That worked perfectly, thanks!
Yes, your ‘connected_query’ would be great; it would avoid two separate queries when all you want is a quick piece of data to set a variable.
Thanks again!
sorry my english is very bad
I’m not getting with this code, could post the full code.
Thank you.
–
(@disonancias)
I just asked how to do it with custom taxonomies, but found out right after posting. In case anyone else needs it:
$articles = new WP_Query( array(
'connected_type' => 'YOUR_CONNECTION_TYPE',
'my_custom_taxonomy' => 'my_custom_term',
'orderby' => 'rand',
'posts_per_page' => 1
) );
Hi there, I am trying to do the same thing. The code above works well, but I am getting duplicate records. Is there a way to remove duplicates via a “distinct” or something? Thanks!
I am posting my code below …
$originals = query_posts( array(
‘fields’ => ‘ids’,
‘post_type’ => ‘original’,
‘mediacategory’ => ‘fine-arts’
) );
$artists = new WP_Query( array(
‘connected_type’ => ‘artist_to_original’,
‘connected_items’ => $originals
) );
If an artist has created multiple originals in the category, they are showing up multiple times in my results.