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:
- Adding a Taxonomy Filter to Admin List for a Custom Post Type?
- I found this in a plugin. What does it do? is it dangerous?
- How to export comments in WordPress?
- Where are plugins located
- Admin menu as submenu from another plugin
- Why does WordPress require a ftp server to be running on the webserver to transfer plugins?
- How to make search engine index PDF files? [closed]
- WordPress Admin is displaying Not Available
- Add content to /wp-admin/plugin-install.php admin screens
- Custom admin column disappearing when using Quick Edit [duplicate]
- 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
- Plugin Development: WordPress processes twice on post update. How to skip process on the first?
- how to not show plugin in admin area
- WP-PageNavi plugin doesn’t work with multiple pages of search results
- “Are you sure you want to do this?” when deactivating all plugins in WordPress 4.3.1 [closed]
- How to make a WP admin button/menu similar to Jetpack Notifications?
- Getting “Fatal error: Call to undefined function wp_cache_get() in option.php” after updating a cache plugin [closed]
- How to improve WordPress search
- Creating search filter through plugin
- How do I add advanced custom fields / meta fields to Elasticsearch? [closed]
- Questions about brute force attacks on the admin username, coming from amazon IP addresses
- Edits to plugin not taking effect
- Can’t see login page after migration
- How can I reuse the WordPress search form for a custom plugin / widget?
- Weird problems after recovery from security breach
- Custom Taxonomy Tag Search
- ‘wp_login’ action hook not working with wp-login.php file
- What is the best way to mimic a search query within a plugin
- 404 Error on Activate / Deactivate Plugin
- Why isn’t admin_notices displaying my text? [Simple Plugin, Beginner]
- Is there a way I can find wordpress posts that don’t contain a word?
- Rotating background images with admin options
- Show an image in my header.php
- How to hide some section in WordPress under Post
- Default WordPress WP Editor removing style tags and html tag
- Facebook Messager Plugin
- Polylang : Interverting languages after development [closed]
- 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
- Calling PHP function with AJAX
- 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
- 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
- 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?
- 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
- wordpress Search function is not working
- ERROR: Cookies are blocked due to unexpected output – no access to FTP
- Ajax in wordpress [duplicate]
- Notifications Bar on home page only
- WordPress Plugin and other pages not opening
- The Admin page isn’t showing in the sidebar of the dashboard
- warning wp session
- Can we install 3d product configurator into wordpress
- Submitting form to admin-post.php WordPress
- /wp-admin/plugins.php takes ages to load, and then 404s
- Stop the user if login from the cookies
- LiteSpeed cache image Optimization
- whole website redirected to another page
- WordPress search every time shows no search found even data exists
- How to Handle? vp_page Parameter in WordPress and Resolve Google Search Console Validation Issues?
- How to add CPT in Elementor pro search template