We are using this code to see if the user has posted, however we wish to exclude admins. Currently if the role is admin, the function returns a post count.

$args = array(
    'post_type' => 'post',
    'post_status' => 'publish',
    'author' => get_the_author_meta('ID'),
    'fields' => 'ids',
$wp_posts = get_posts($args);
if(count($wp_posts)) : ?>

I tried 'role' => 'contributor' in the $args but the admin is still being included.

  • 1
    So you don't want any of this code to run if the current user is an admin? There are no role related options for get_posts, but for what you want to do the get_posts call is irrelevant, just check if the author is an administrator and wrap the whole thing in an if statement. I also edited your questions code example as it was all smushed on to a single line, and was unreadable. Please put 1 thing per line so it's readable, and indent properly, don't try to save space – Tom J Nowell Jul 30 '19 at 15:36
  • Toms suggestion is probably the best option. Maybe wrap this statement around your query: if( is_user_logged_in() && !current_user_can('administrator') ) { // DO QUERY } – Louis S Jul 30 '19 at 15:46
  • I am using this code to output the authors bio, in the wp-single.php - So I am not sure if I can use your suggestion. I will prob need some code inside the IF argument to check if the article was created by the admin ? – Joanna Mikalai Jul 30 '19 at 16:19

Your Answer

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

Browse other questions tagged or ask your own question.