For regular admin panel search you should include “is_admin()” to be true.
For checking for specific post type you should check from $query->get("post_type")
Can you try to use this code
add_action("pre_get_posts", function ($query) {
if ($query->is_main_query() && is_admin() && in_array($query->get('post_type'), array('company'))) {
$s = get_search_query();
$meta_query = [
'relation' => 'OR',
[
'meta_key' => '_company_inn',
'value' => $s,
'compare' => 'LIKE',
],
[
'meta_key' => '_company_phone',
'value' => $s,
'compare' => 'LIKE',
],
];
$query->set("s", $s);
$query->set("meta_query", $meta_query);
}
return $query;
});
Related Posts:
- Plugin for better Backend Search? [closed]
- How to Add a Third Level Sub Menu to the WordPress Admin Menu
- How to export comments in WordPress?
- Why does WordPress require a ftp server to be running on the webserver to transfer plugins?
- WordPress Admin is displaying Not Available
- Add content to /wp-admin/plugin-install.php admin screens
- Plugin: How to make links in admin page open up inside of the admin panel
- Search and replace text across all posts
- How to remove/hide action links cluttering under specific plugins’ names
- How would implement StackExchange ‘Questions with similar titles’ for the FAQ on my wordpress site
- Adding Visibility Options
- How to get posts by content?
- Problem with Search Results in WP (not displaying the full posts)
- Creating search filter through plugin
- Questions about brute force attacks on the admin username, coming from amazon IP addresses
- Why would WP-CLI and WP Admin show different list of plugins with updates?
- How could I execute my plugin just in frontend (not in backend)
- Automatically adding category filter based on search string
- Can’t see login page after migration
- Custom height/width for thickbox in WP Backend
- Hide Theme options and Customize Admin menu
- How can I create a plugin installation link?
- Cannot access wp-admin after disabling all plugin
- Custom Taxonomy Tag Search
- What causes an Unexpected HTTP Error within install plugins?
- How to provide a plugin which requires CMB2 (plugin dependencies)?
- Is there a way I can find wordpress posts that don’t contain a word?
- Plugin upload to install
- Change the backend language of a single plugin
- Search is not working on plugin directory
- Rotating background images with admin options
- Show an image in my header.php
- Facebook Messager Plugin
- Is it possible make a back-end for WordPress with WordPress?
- Create tabs in admin options page from custom post type loop
- Remove ‘Check Compatibility’ from Plugins menu
- AJAX search as you type? [duplicate]
- WooCommerce search products between price range using WP_Query
- Add sub menu page in your plugin
- Send admin an email when a user’s search has no results
- Full list of registered scripts or styles, but from an admin options page
- How can i force wp-admin to use 2-column dashboard layout? [closed]
- How can I modify page content in the admin panel?
- How to display terms and conditions in post area?
- How to set “split_on_numerics” to false in ElasticSearch mapping using ElasticPress? (for proper SKU search in WooCommerce) [closed]
- Change the layout of action links under the plugin names
- getting notifications about updates only in the “core” page
- Search and Filter Plugin – How to disable redirection
- WordPress Multi-Step Product Search
- Remove value from array within post meta ajax admin
- Is there a better way of handling AJAX requests in WordPress?
- Get access to WordPress when logged out
- Why are plugin settings not all nested in one place?
- Edit page header on a custom plugin
- 404 errors when updating options in admin dashboard
- Error activating certain plugins
- How to search post titles with whole words only, but not the exact word only?
- RSS feeds for specific topics
- WC Fix Attributes – ‘Add New’ Not Searchable/Delayed
- How can we get this dynamically as this folder may not be by the same name always → wp-admin
- Calling PHP function with AJAX
- Redirect to a page while maintaining search query parameters without causing an infinite loop
- Failed GET Request From admin.php To Fetch .min.js File From Unminifed Directory
- How to find where an image is used by it’s url
- WordPress Admin login redirect to homepage
- Store admin page into variable
- Admin login substantially slower on production server
- Continous audio play in pages
- How to make wp multisite subdomain exist search
- Remove Url Parameter WordPress
- How can I remove this sidebar from my Search Results page?
- History of page, interval of years
- Include post_date in search
- How to hook into search results template or query?
- Admin Logged In Notify Globaly
- Disable default posts (Posts,Pages,Comments and Media) in wp-admin
- WordPress Search return wrong results
- wp-admin will not redirect to wp-login.php
- Getting 404 page not found error while trying to access add new plugin / themes
- getpost content with all formatting for admin pages
- Plugin (smart archives reloaded) crashed site / no access on admin panel
- Is there any simple wordpress search template that works with existing searchforms?
- Extend WordPress Search
- How to activate/deactivate menu tab and keep the same id?
- Making plugin to use different table prefix cause permission problem
- Strange Search Query Appearing on Google Index – “/?q=Save+Us+From+Berlusconi”
- Add custom fields in the new and edit the site forms without touching the WP core
- Ajax in Plugins: returns the whole page
- wordpress Search function is not working
- ERROR: Cookies are blocked due to unexpected output – no access to FTP
- Notifications Bar on home page only
- Allow direct access to files/folders within WordPress to replace wp-admin
- WordPress website is redirecting on some different shopping page
- How to set an exact search box in tablepress plug-in
- Autocomplete search field that is feed by a taxonomy from custom post type?
- Create index for own custom data in elasticpress from wordpress plugin
- Fatal Error in my WP “Call to undefined function get_option()”
- Secure way to add JS Script to WordPress filesystem
- Not applying update field (acf) in my plugin
- Force post update with React