# Look Up Posts by URL Slug From Admin Lists

> Lets you type slug:my-post-name into the search box of any admin post list to find the item with that URL slug, which is handy when you only have a link.

- Type: PHP
- Runs: Admin only
- Category: [Admin](https://wpide.com/library/category/admin/)
- Tags: admin-search, slugs, posts
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/admin-search-by-slug/

## Code

```php
add_action( 'pre_get_posts', function ( $query ) {
    if ( ! is_admin() || ! $query->is_main_query() || ! $query->is_search() ) {
        return;
    }

    $search = trim( (string) $query->get( 's' ) );
    if ( 0 !== stripos( $search, 'slug:' ) ) {
        return;
    }

    $slug = trim( substr( $search, 5 ) );
    $path = wp_parse_url( $slug, PHP_URL_PATH );
    $slug = sanitize_title( basename( untrailingslashit( $path ? $path : $slug ) ) );

    $query->set( 's', '' );
    $query->set( 'name', $slug );
    $query->is_search = false;
} );
```

## Notes

You can also paste a full URL after "slug:"; only the last part of the path is used.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Look Up Posts by URL Slug From Admin Lists" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
