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]
- 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?
- Disable /wp-admin/plugin-install.php
- Is admin section completely customizable in terms of styling?
- Store admin page into variable
- how to add navigation icons in specific template?
- Not able to upload Plugins/ Theme from Admin backend
- Admin login substantially slower on production server
- multiple string replace of post’s content for large data
- wordpress plugin translation not working
- How can I make the search bar in my wordpress site search all of the pages rather than just the blog posts?
- Why does WordPress use cookies for /wp-admin and /wp-content/plugins for non-admin users [duplicate]
- How can I share my wordpress site with a friend?
- Continous audio play in pages
- Set plugin page as homepage
- 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 order users alphabetically by name? in plugin UPME
- Disable plugin on admin page
- How to hook into search results template or query?
- The Commercial tab is missing from the Plugins page when trying to update Types 1.7
- Add “selected” class to custom taxonomy dropdown search
- Admin Logged In Notify Globaly
- Disable default posts (Posts,Pages,Comments and Media) in wp-admin
- WordPress Search return wrong results
- Ajax return 0 in plugin – ajax only used in wp-admin
- wp-admin will not redirect to wp-login.php
- Differentiate attachment pages in search results
- How to add php stylesheet to admin section instead of admin_head hook
- 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 sort results by last day update at search result in plugin installer?
- Which filters or actions involve with index page for plugin?
- How to activate/deactivate menu tab and keep the same id?
- Jigoshop search taxonomy
- 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
- Gutenberg: Dynamic Block – Show saved data in the editor
- Get post id in Post Page within Wp-admin
- Dave’s WordPress Live Search only works when logged in as admin
- AdBlock blocks my non-advertising sidebar images [closed]
- wordpress Search function is not working
- Multi-step, live updating search
- Combining JS files to one script
- How do I add custom fields to the “Edit page” admin screen?
- Screen Options drop-down does not show
- ERROR: Cookies are blocked due to unexpected output – no access to FTP
- Mixed content warning on doctype in admin
- Child Plugin Admin Panel
- Ajax in wordpress [duplicate]
- Notifications Bar on home page only
- List all posts in a particular page [closed]
- plugin translations not reflected in admin dashboard
- How to display content depending on the Woocommerce Product Category
- Allow direct access to files/folders within WordPress to replace wp-admin
- 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
- WordPress website is redirecting on some different shopping page
- PHP FATAL ERROR
- 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
- How to set an exact search box in tablepress plug-in
- 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?
- Autocomplete search field that is feed by a taxonomy from custom post type?
- How to add CPT in Elementor pro search template
- 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
- Product Search by ZIp Code Radius
- Form submission issue in wordpress admin (custom plugin) using $_GET for searching & filtering
- redirect logged users to custom front-end insetad of wp-admin
- What is the best way to ignore wordpress administration using add_filter($title) also when Ajax request
- Search results not finding in paginated pages just in visible rows
- How do I output translated text strings on edit screens
- I want to create a search option for CPT using plugin. The search options should search for categories and tags
- 403 forbidden error in the admin panel as well as on the admin-ajax.php file
- Search result page admin panel – display values from the result’s metaboxes
- The sidebar in wp-admin dashboard disappears when viewed on mobile screens in WordPress
- media_sideload_image only works on localhost and without return id or src
- How do I apply different block supports to different parts of my custom block?
- Show only those pages that are created by the specific logged in user in WordPress
- Prevent WordPress Link Editor from Automatically Adding “http://”
- Shipping Refund via Stripe Creates New Order Instead of Updating Original Order