To change the search form, filter get_search_form
. You get the form as a string here, and you can change it as you need.
add_filter( 'get_search_form', function( $form )
{
// Replace the form, add additional fields
return $form;
});
To change the search query to the database, filter posts_search
. You get the query as a string and the current WP_Query
object which provides more information. See wp-includes/query.php
for context.
add_filter( 'posts_search', function( $search_query, $wp_query )
{
// change the SQL
return $search_query;
}, 10, 2 );
If you don’t want to filter the search query, change the name
attribute in the search form, example foo
, and inspect the $_POST
request:
if ( ! empty ( $_POST['foo'] ) )
{
$global $wpdb;
$results = $wpdb->get_results( /* custom sql */ );
}
Related Posts:
- How do I improve this admin query snippet to avoid generating duplicate results on non-meta searches?
- How to make dynamically-generated content searchable in WordPress?
- Displaying search results in the widget itself?
- modify wordpress default search
- what are the checksums surrounding keywords in the SQL generated by WP_Query and do I need to use them too?
- Search the product by tag or category not working
- Search and Filter
- Using ob_get_content to get_search_form puts into infinite loop
- How can I replace the search results displayed by WordPress?
- Showing results from json-string in WordPress search results page
- Ajax action has 200 status but response of No response data available for this request
- ajax stopped working when not logged in wordpress
- Get search result count in plugin
- Generate Static Page to Show Search Results/Detail for API
- Modify search form with plugin
- WP Query Relations / Compare
- WordPress Search Form with Keyword Suggestion
- Simple Search Plugin Does Not Perform Search
- How to search on the field that stores escaped strings?
- Change the search results header from plugin
- Get custom wp_query search results to appear on search.php
- Why is WordPress wrapping search for users that looks like integers with asterisks and how do I fix it?
- Hook a search form anywhere on the site, using a custom plugin
- How do I create a custom role capability?
- What is the advantage of using wp_mail?
- Calling the widget id of a mult-instance widget from inside the widget?
- Do I need to call do_action in my plugin?
- Fatal error: Call to undefined function wp_mail()
- WooCommerce get Shipping Class of product from either the product id or the order after order is completed
- Dequeue script, but still use wp_localize_script to pass vars
- I can’t find where a hook is being defined in a plugin – Easy Digital Downloads
- Can I add pages to my custom menu via script?
- Replacing WordPress menu functionality with a plugin
- Programmatically Selecting Theme Based on URL
- Is it possible to load plugin from console with core ?
- Plugin development: is adding empty index.php files necessary?
- Plugin base URL
- Database for development
- Customize multisite site creation with user data
- Adding plugin settings link upon activation
- How to create multiple Gutenberg blocks in one plugin
- How to disable reCaptcha v3 except on Contact Form 7 pages?
- Fetching the value of forms in WordPress AJAX
- What is the best way to mimic a search query within a plugin
- How to add setting section in custom post type [closed]
- Get Current Menu Location inside Nav_Walker
- Append country to ‘pretty’ url but serve same page
- Where to add hooks in a class
- Insert terms for custom taxonomy on plugin activation, or each page load (init hook)
- Adding a brand column to WooCommerce Products
- Custom GET Parameters In Plugin’s Admin Page
- Adding option to Gallery shortcode
- WordPress Search filter to remove possible script injections
- Incorporate small angular feature in my wordpress site
- Bootstrap doesn’t work on admin menu page-How to override wp-admin style?
- WordPress class, using add_action to call member function does not work
- random code at the end of file after plugin upload
- How Can I add Fields in wp-option table?
- Where do I put my add_action(… and add_filter(… and do I need to remove them?
- ajax recursive calls on wordpress returning answers outsite the function scope
- Custom Empty Results page for my Custom Post Type
- WordPress pages are not published due to External database connection with WPDB class
- How can I show posts for a single category?
- In wordpress plugin wp_signon shows error
- How to find where an object first instantiatiation
- Problem with autoloader and namespaces
- Clean way to initialize plugin in newly-added site when plugin has been network activated?
- How to deal with different jQuery versions?
- Can I attach a plugin via my add_filter callback contents?
- How to trigger selected option from a clic. (variation product woocommerce)
- WordPress Favicon not Working For Images/Videos/PDFs
- Is “document loaded” different on admin side than public side?
- how to handle premium features in a wordpress plugin?
- Show username only if logged in in a else no directly name
- Yoast and another plugin
- Handle changed Woocommerce function
- Making Woocommerce optimized for more than 500k products
- How to set custom homepage via a plugin
- Add placeholder into contact form 7 recaptcha text field
- To remove rendering of menus and header, plugin or theme?
- the correct way to use options from settings page [closed]
- I want to add post meta for picture thum during submit for revision
- How to synchronize an e-commerce site and a pharmacy management software?
- woocommerce features to add product along with link
- wp_head is not fired from the hook I have used in my plugin
- Admin Message after Plugin Option Updated
- How react js and other Javascript Technologies works on WordPress plugin?
- Shortcode rendered in preview, but empty in post
- Trigger a JavaScript function based on the data fetched from Woo commerce hook
- Add custom data-attribute to core Gutenberg block within an template
- Can I log the searches that are returning 404 in the DB?
- Install a MU plugin from within another plugin
- Do Not Back Up? Is there any accepted way to tell backup and clone plugins to skip a certain file? [closed]
- get_the_tags($ID) is empty during publish_post callback
- Can we install 3d product configurator into wordpress
- wp cron does not run when i am not logged in to wp admin
- update_option with array_push adding mutiple copies
- How to enable auto update for embedded plugins
- My activator class isn’t running the code inside
- Remove Gutenberg Buttons Block