Hi,
I'm using the Co Author plus plugin,
and I can't figure out how to retrieve all the posts by one (co) author knowing the plugin is using taxonomies.
Any tips? thanks.
Hi,
I'm using the Co Author plus plugin,
and I can't figure out how to retrieve all the posts by one (co) author knowing the plugin is using taxonomies.
Any tips? thanks.
WP_Query is your friend. Something like this should work:
$author_posts = new WP_Query( array( 'author' => $author_login ) );
I tried that,
it does not work : my query is to retrieve my author posts in a certain category, it retreives me all the posts of that category, ignoring the author.
In that case, you'll want to use a tax query to query multiple taxonomies.
Ok,
could you be more specific?
As i see in the WP_Query example :
$args = array(
'tax_query' => array(
array(
'taxonomy' => 'people',
'field' => 'slug',
'terms' => 'bob'
)
)
);
In the case of the co authors, what taxonomy am I supposed to use?
Same question for the 'field' parameter.
I suppose i have to put my user_login for the 'terms' parameter.
To have a more specific example :
I have to retrive all the posts, in the category 'news' from my author 'john-smith' (who is a secondary author thanks to the co author plugin, not the primary one)
Something like this should work:
$args = array(
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => 'news'
),
array(
'taxonomy' => 'author',
'field' => 'slug',
'terms' => 'john-smith'
)
)
);You must log in to post.