You haven’t provided much info so I will give you a basic example.
You need to find whatever template your theme is using to display the results, possibly search.php. If this isn’t your theme create a child theme and duplicate the file that displays the results.
This file should already have an if
statement for displaying the results, possibly an if/else
. If not you will need to add one. The Else is used for when there are no results. You can grab what was entered in the search with get_search_query().
Inside the else you can use wp_mail() to send an email.
For Example:
if ( have_posts() ) : while ( have_posts() ) : the_post();
// Code to display your results
else:
// No results so send an email
$query = get_search_query();
$to = '[email protected]';
$subject="User Search";
$message="User searched " . $query;
wp_mail($to, $subject, $message );
endif;
Related Posts:
- Disable email notification after change of password
- wp_mail and BCC headers
- Sending all emails using SMTP
- How to get current post ID in Contact Form 7 wpcf7_before_send_mail hook action
- How to make search engine index PDF files? [closed]
- Send email when a new post is published [closed]
- Email Notifications of new posts to users – suggestions [closed]
- How to override normal WordPress search in Buddypress? [closed]
- Search and replace text across all posts
- How would implement StackExchange ‘Questions with similar titles’ for the FAQ on my wordpress site
- How to add usermeta to “Notice of Email Change” email message
- Notify commenters about new replies
- dynamic page not indexed
- How to get posts by content?
- WP-PageNavi plugin doesn’t work with multiple pages of search results
- Send batch of posts as HTML Email?
- Problem with Search Results in WP (not displaying the full posts)
- Is there a plugin that allows a user of your site to get an email from you with an attachment?
- Plugin for Sending Email to Readers about New Posts? (besides “Subscribe2 “)
- How to improve WordPress search
- How to bulk send emails
- Server-side subscribe by email?
- WP Mail SMTP: What do the SSL/TLS options mean? [closed]
- Creating search filter through plugin
- How do I add advanced custom fields / meta fields to Elasticsearch? [closed]
- wp_mail() is not working on server
- Storing a password for use with a WordPress plugin
- plugin to search entire posts, blogs, forum, users [closed]
- A very basic question – how to properly use wp_mail() in a plugin
- WordPress plugin for mail subscriptions [closed]
- Is there a plugin to record querystring parameters for a page (for customer tracking)? [closed]
- Storing Email Account Passwords for SMTP Mailing for a WordPress Plugin
- action-scheduler vs wp-background-processing
- Automatically adding category filter based on search string
- Easy Digital Downloads (EDD) – Purchase Receipt emails couldn’t be logged
- How can I reuse the WordPress search form for a custom plugin / widget?
- WordPress sending emails continuously. How to stop it?
- wp_mail attachment not working
- Setting Custom Email From name and email address in wp_email()
- how to incude logo in contcat form 7 email [closed]
- Check if email address exists front end with AJAX in a plugin
- Custom Taxonomy Tag Search
- What causes an Unexpected HTTP Error within install plugins?
- Woocommerce email template customization [closed]
- Sending email from inside a plugin using PHP PEAR
- What is the best way to mimic a search query within a plugin
- Can’t send mails using contact plugin [closed]
- Is there a way I can find wordpress posts that don’t contain a word?
- Hook into and send mail using WP Mail SMTP type plugin from HTML static front page?
- Email Bounce Address
- Search is not working on plugin directory
- WordPress Registration Email by Role
- Search Everything plugin integration
- AJAX search posts and pages
- Get sent emails without email logs
- How to send an automated email to the customers when product is added woocommerce
- Search for categories
- Looking for a way that will collect visitors emails before letting them view the blog posts [closed]
- How to hook into search results template or query?
- Add “selected” class to custom taxonomy dropdown search
- WordPress Search return wrong results
- Differentiate attachment pages in search results
- Setup SMTP setting in wordpress
- How do I replace the e-mail form to functional e-mail subscription? [closed]
- 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?
- Overwrite CSS of Instaemail plugin popup
- Jigoshop search taxonomy
- Choose User to email when adding a new post?
- Automatically send an email to list when blog is updated
- Strange Search Query Appearing on Google Index – “/?q=Save+Us+From+Berlusconi”
- Dave’s WordPress Live Search only works when logged in as admin
- wordpress Search function is not working
- Multi-step, live updating search
- How to work email subscribe in WordPress?
- Send Processing Order Email from custom payment plugin
- Send email notification when meet the condition
- Woocommerce Emails not being sent [closed]
- WP can’t send newsletters
- WordPress isn’t sending welcome email with the password reset
- Can we install 3d product configurator into wordpress
- LiteSpeed cache image Optimization
- How to set an exact search box in tablepress plug-in
- additional fields based on the quantity of products selected
- 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
- search by meta field in the regular WordPress admin panel search
- Email notification when registred user clicks a link/visits page
- Product Search by ZIp Code Radius
- Search results not finding in paginated pages just in visible rows
- How do I set WordPress to send 2 different emails based on criteria in the database when someone submits a form?
- SMTP email does not work even with the right firewall rules
- I want to create a search option for CPT using plugin. The search options should search for categories and tags
- Plugin for better Backend Search? [closed]
- How do I apply different block supports to different parts of my custom block?