To ignore dots (.
) in the search parameter s
, for all backend searches, we can use:
/**
* Ignore dots in all backend searches
*/
add_action( 'pre_get_posts', function( \WP_Query $q )
{
if ( is_admin() && $q->is_search() )
$q->set( 's', str_replace( '.', '', $q->get( 's' ) ) );
} );
We can further restrict it to the list
mode of the Media Library:
/**
* Ignore dots in all media library searches, for the 'list' mode
*/
add_action( 'pre_get_posts', function( \WP_Query $q )
{
if (
is_admin()
&& $q->is_search()
&& $q->is_main_query()
&& 'upload' === get_current_screen()->id
&& 'list' === filter_input( INPUT_GET, 'mode' )
)
$q->set( 's', str_replace( '.', '', $q->get( 's' ) ) );
} );
If we only want to target the ajax searches, that includes the grid
mode of the Media Library and the Insert Media popup:
/**
* Ignore dots in ajax searches
*/
add_filter( 'ajax_query_attachments_args', function( $args )
{
if( isset( $args['s'] ) )
$args['s'] = str_replace( '.', '', $args['s'] );
return $args;
} );