0

I'd like to use query_posts() to show only posts from editors and administrators on my home page so that normal authors can post on their own pages, but not affect the home page.

Edit :

Thanks for the quick reply, I'm a bit of a novice when it comes to php, do you think you could give me the code I require? I'm currently using this, but getting no posts returned despite having several posts by an administrator:

$wp_user_search = new WP_User_Query( array( 'role' => 'administrator' ) );
$admins = $wp_user_search->get_results();
$args = implode(',', $admins);
query_posts("author=$args");
2
  • This is exact opposite of this question Hide posts from users with a specific role check out my answer there and if it fits I will probably close this as duplicate. – Rarst Jul 13 '11 at 18:56
  • @Rarst: the answer to this question is exactly the same minus the minus sign ( - ) in the query parameters but i guess its still something a lot of people would look for and not the other way around. – Bainternet Jul 13 '11 at 19:14
1

Code you are after:

<?php
$wp_user_search = new WP_User_Query( array( 'role' => 'administrator' ) );
$admins = $wp_user_search->get_results();
$admin_ids = array();
foreach($admins as $admin) {
    $admin_ids[] = $admin->ID;
}
$args = implode(',', $admin_ids);
query_posts("author=$args");
?>

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.