How to remove the admin role from the Author listing screen from the individual post? Which hook to use to do this? Can anybody help me? enter image description here

Check the above screen

  • This is not a role, but the authorship to be assigned to the post. Also, this field is visible to the admins and the editors only if not explicitly specified otherwise.
    – Max Yudin
    Commented Jan 22, 2017 at 9:30
  • I did it but I need to pass array and I am stuck with it $user_search->query_where = str_replace('WHERE 1=1',"WHERE 1=1 AND {$wpdb->users}.ID<>1 AND {$wpdb->users}.ID='".$selected_author_id[0]."'",$user_search->query_where);...In place of $selected_author_id[0] I need to pass array but if I pass array its not giving any result can anyone help?
    – 1991wp
    Commented Jan 22, 2017 at 14:50
  • Please edit your question according to your comment and make clear what you are trying to achieve.
    – Max Yudin
    Commented Jan 22, 2017 at 17:57

1 Answer 1


This is the answer for my above Question

function ap_pre_user_query($user_search) {
  $user = wp_get_current_user();
  if ($user->ID!=1) { // Is not administrator, remove administrator (you can add any user-ID)
    global $wpdb;
    global $user_ID;
    //Fetch the custom field value added in user section
    $meta = get_user_meta( $user_ID );
    $selected_author_id = unserialize($meta['select_md'][0]);
    $count = count($selected_author_id);
    //to the data you got add the current user to it
    $selected_author_id[$count] = $user_ID;
    $store_ids = '';
    foreach($selected_author_id as $ids){
        $store_ids .= $ids.',';
    $final_ids = rtrim($store_ids,',');
    //This query will return you the result you want
    $user_search->query_where = str_replace('WHERE 1=1',"WHERE 1=1 AND {$wpdb->users}.ID<>1 AND {$wpdb->users}.ID IN (".$final_ids.")",$user_search->query_where);

Check the output below enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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