# Find Posts by ID in the Admin Search

> Type #123 or id:123 in the posts or pages search box to jump straight to the item with that ID.

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

## Code

```php
add_action( 'pre_get_posts', function ( $query ) {
    global $pagenow;

    if ( ! is_admin() || ! $query->is_main_query() || 'edit.php' !== $pagenow ) {
        return;
    }

    $search = trim( (string) $query->get( 's' ) );

    if ( preg_match( '/^(?:#|id:\s*)(\d+)$/i', $search, $match ) ) {
        $query->set( 's', '' );
        $query->set( 'p', (int) $match[1] );
    }
} );
```

## Notes

Plain numbers are still searched as text, so titles like "2025" keep working.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Find Posts by ID in the Admin Search" 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/
