Here's one way to support searching for post slugs in the backend.
Let's invoke this kind of search by the slug:
string in the search term.
Example
To search for slugs that end in -2
we want to be able to search for:
slug:*-2
where * is the wildcard.
Demo Plugin
Here's a demo plugin that might need further testing and adjustments:
add_filter( 'posts_search', function( $search, \WP_Query $q ) use ( &$wpdb )
{
// Nothing to do
if(
! did_action( 'load-edit.php' )
|| ! is_admin()
|| ! $q->is_search()
|| ! $q->is_main_query()
)
return $search;
// Get the search input
$s = $q->get( 's' );
// Check for "slug:" part in the search input
if( 'slug:' === mb_substr( trim( $s ), 0, 5 ) )
{
// Override the search query
$search = $wpdb->prepare(
" AND {$wpdb->posts}.post_name LIKE %s ",
str_replace(
[ '**', '*' ],
[ '*', '%' ],
mb_strtolower(
$wpdb->esc_like(
trim( mb_substr( $s, 5 ) )
)
)
)
);
// Adjust the ordering
$q->set('orderby', 'post_name' );
$q->set('order', 'ASC' );
}
return $search;
}, PHP_INT_MAX, 2 );
This is based on the _name__like
plugin in my previous answer here.