I try to find all the articles associated to an author, even those reallocated to another author in the meantime. Have you any ideas about that ? Thank you in advance !
CodePudding user response:
Yes, it's simple. First get all the users with author
role and then pass those user_ids to WP_Query()
.
To get user_ids
:
function author_ids_by_role() {
$user_ids = get_users(array('role' => 'author' ,'fields' => 'ID'));
return $user_ids;
}
Now, in WP_Query()
:
$user_ids = author_ids_by_role();
$args = array(
"posts_per_page" => 10,
"post_type" => "post",
"author__in" => $user_ids
);
$wp_query = new WP_Query( $args );