Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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");
share|improve this question
    
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 Answer 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");
?>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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