Disable – Post search field – for non-admin roles in WP dashboard

There is no straight forward documented way of removing the search box in the admin panel’s Post dashboard (wp-admin/edit.php).

However, it’s still possible by extending WP_Posts_List_Table class.

Additionally, it makes sense that if you remove the search box, you’d also like to disable the search capability all together (based on your requirement).

In that case, you may redirect any search request to the default wp-admin/edit.php page. That’ll effectively disable any manual search attempts.

Following is a fully functional example plugin code that demonstrates how this can be implemented:

<?php
/**
 * Plugin Name: @fayaz.dev Remove post search in dashboard
 * Description: Remove post search option in wp-admin/edit.php for users who don't have the capability to edit other's posts. 
 * Author: Fayaz Ahmed
 * Version: 1.0.0
 * Author URI: https://fayaz.dev/
 **/

namespace Fayaz\dev;

function init_search_box_removal() {
    if( is_admin() && ! wp_doing_ajax() && ! current_user_can( 'edit_others_posts' ) ) {
        // disable search capability
        if( isset( $_REQUEST['s'] ) ) {
            wp_safe_redirect( admin_url( 'edit.php' ) );
            exit;
        }

        // remove the search box
        add_filter( 'wp_list_table_class_name', '\Fayaz\dev\define_wp_posts_list_table', 10, 2 );
    }
}
add_action( 'set_current_user', '\Fayaz\dev\init_search_box_removal' );

function define_wp_posts_list_table( $class_name, $args ) { 
    if( $class_name === 'WP_Posts_List_Table' ) {
        class WP_Posts_List_Table_Search extends \WP_Posts_List_Table {
            // this just overrides WP_List_Table::search_box() method.
            // the overriding function here does nothing,
            // hence it effectively removes the search box
            public function search_box( $text, $input_id ) {}
        }
        return '\Fayaz\dev\WP_Posts_List_Table_Search';
    }
    return $class_name;
}