Here’s an alternative way to only make the product
post type searchable, from a plugin code:
<?php
/** Plugin Name: Product Search Only **/
add_filter( 'register_post_type_args', function( $args, $post_type )
{
$args['exclude_from_search'] = true;
if( 'product' === $post_type && (bool) $args['public'] )
$args['exclude_from_search'] = false;
return $args;
}, 999, 2 );
Here we modify the post type registration, by setting the exclude_from_search
to true, for all post types, except the public product
post type. If needed you can adjust the late priority.
Related Posts:
- Search and Filter
- Using ob_get_content to get_search_form puts into infinite loop
- Difference Between Filter and Action Hooks?
- How to add sub-menu to a menu generated by wp_nav_menu by using plugin
- How can I load a page template from a plugin?
- Using query_vars filter
- How to make dynamically-generated content searchable in WordPress?
- How to get Post ID with the Add Filter Function
- Explanation of the “posts_join” and “posts_fields” filter hooks?
- Is it possible to remove next-post / previous-post with out creating a custom template?
- How do I Make a Theme “plugin-ready”?
- Proper way to use apply_filters() with class functions?
- How to modify post content before writing to database?
- Actions or filters fired when data is saved in a custom table
- Filter on the_content ignores shortcodes
- Determine which theme location a wp_get_nav_menu_items is for
- How to change wordpress post title?
- Displaying search results in the widget itself?
- Display only certain posts based on visitor’s country?
- What’s the difference between hooks, filters and actions? [duplicate]
- How to use filter hook ‘post_updated_messages’ in coherence with action hook ‘save_post’
- Conditional add_filter?
- Is it possible to create an action hook using do_action() within add_action()?
- Hook for post permalink update
- Dynamically Override Fancy Title
- Calling apply_filters on non-documented hooks
- How to allow Unfiltered HTML in a wordpress multisite install
- Changing bloginfo description from a plugin
- Is there a way to verified if an add_filter is already applied?
- Does add_filter work outside functions.php
- multiple functions with same filter
- Woocommerce – Hide a Column in Cart Table
- Version upgrade: can my plugin filter the SQL statements issued during a database upgrade?
- add_filter : Passing an array instead of the callback function?
- How do I alter the comment form ‘allowed tags’ text in a plugin?
- WordPress after content Hook & external template part
- Namespaced action and filter tags
- Two functions utilizing registration_errors filter
- Is there a Filter that I can use to filter the tags before they are inserted in to the database?
- WordPress is automatically linking plain text email addresses
- Why doesn’t my simple the_title filter get applied?
- modify wordpress default search
- How to filter the_content() & include content from template
- Adding rewrite rule dynamically
- Prefixing plugin hooks (actions/filters) with a wrapper class or functions
- Can’t get woocommerce_get_price_html to work [closed]
- WordPress custom taxonomy check box to dropdown
- WordPress class, using add_action to call member function does not work
- How can I replace the search results displayed by WordPress?
- Remove an action by extending class and replacing it
- hook filter after the_content on a specific page
- Bind a function with its own argument to show something dynamically after every content
- Hook add_attachment error
- Call to undefined function is_home() or any conditional tags
- WooCommerce change Tax Class programmatically when Recalculating an existing Order [closed]
- Update variable value via add_filter
- Gravity Forms Anchor only on Front Page?
- How to find list of all functions bind to a particular hook from my plugin?
- Include HTML (Bootstrap Modal Box) with a plugin into my header
- WP_NAV_MENU filter targets all menus
- How do i remove the title from a specific page
- Can / should a widget plugin define its own Widget Area?
- How to get changed post title in my custom plug-in which fires when ‘save_post’ is called?
- Is there an action_filter hook to add content before the post title?
- Adding tables to dashboard pages programmatically?
- Can I attach a plugin via my add_filter callback contents?
- Showing results from json-string in WordPress search results page
- add_filter postbox_classes multiple post types
- Override category archive page title (not the head title)
- Limit get_next_post to posts from the same author
- ajax stopped working when not logged in wordpress
- Get search result count in plugin
- Override woocommerce loop-start.php from theme using plugin?
- Any way, hook to add content right before the “read more” link?
- Generate Static Page to Show Search Results/Detail for API
- WordPress Plugin Boilerplate – add actions and/or filters based on user’s role
- Redirect theme directory to plugin theme directory
- WordPress Reset password Strength set to medium
- Change Front page displays settings conditionally when user is online
- login_message filter not working
- WordPress Dropdown image select
- Single_template for a custom post type created from a plugin is returning an empty page
- WP Query Relations / Compare
- WordPress Search Form with Keyword Suggestion
- Caption Shortcode: what filter to change the image size?
- Confusing $tag specification for apply_filters call, in core options.php code
- Hook for plugin to show content for certain urls
- Simple Search Plugin Does Not Perform Search
- How to search on the field that stores escaped strings?
- WordPress permalink setting
- Change the search results header from plugin
- How to create a custom search form and handler?
- Apply Filters Causing a 500 Internal Server Error
- wp_mail_from not changing from address
- append code after the_content not working
- add_filter adds output in the head
- Apply function on all action hooks?
- Do Not Back Up? Is there any accepted way to tell backup and clone plugins to skip a certain file? [closed]
- Why is WordPress wrapping search for users that looks like integers with asterisks and how do I fix it?
- Ninja Forms: Front-End Forms, Post ID?