0

Firstly I get user with role "author".

$author_args = array(
'role' => 'author'
);
$authors_list = get_users($author_args);

Nextly I reform array

$author_list = array();
foreach((array)$authors_list as $author) $author_list[] = $author->user_nicename;

And then finally query args

$author_posts_args = array(
        'author_name' => $author_list,
        'post_type' => 'post',
        'cat'  => $colecti_id,
        'posts_per_page' => '4',
);
$author_posts_query = new WP_Query($author_posts_args);

Why it doesn't works?

1

get author ids instead of author nicename to get posts for muliiple authors using WP_Query();

$author_list = array();
foreach((array)$authors_list as $author) $author_list[] = $author->ID;

// make comma separated string from author ids array
$author_list = implode(',', $author_list)

and change wp query args

$author_posts_args = array(
    'author' => $author_list,
    'post_type' => 'post',
    'cat'  => $colecti_id,
    'posts_per_page' => '4',
);
$author_posts_query = new WP_Query($author_posts_args);
  • Yep! It works. Thank you. I looked in the Codex and there were written about 'author' arg that it uses (int), so I thought that I can't use strings or arrays. Poor me. – okonik Sep 9 '13 at 18:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.