If you collect feedback, reviews, and other information through forms, then you can make this data searchable on your WordPress site.
Unfortunately, WordPress’s default search function doesn’t include form data. This means that valuable information is essentially hidden from users.
But with SearchWP, you can easily include form submissions in the search process. Whether you’re managing surveys, reviews, or any other type of form, SearchWP will help make this content discoverable.
In this article, we’ll show you how to include WordPress form submission in search results.
Why Include Form Submissions in WordPress Search?
Making form submissions searchable in WordPress can significantly enhance the functionality and user experience of your website.
Users often submit information through forms and may need to access or recall what they submitted later. By including form submissions in search, you allow users to quickly find their own submissions without needing to contact site administrators.
For example, if a user submitted a support request or an application, they can easily search and find their submission to check its status or review the details.
Form submissions also contain valuable content that might not be readily available elsewhere on your site. This could include user-generated content from surveys, feedback forms, or comment forms.
It also helps avoid duplication, as users can search for a particular form submission instead of creating a new one.
That said, let’s take a look at how you can easily include form submissions in WordPress search.
Make Form Submissions Searchable in WordPress
The easiest way to search different forms in WordPress is by using SearchWP. It is the best search plugin for WordPress and offers powerful extensions for some of the most popular contact form plugins.
Currently, SearchWP supports WPForms and Gravity Forms. It makes it easy to add forms from these plugins as a search engine source, so users can easily search and discover form content.
Besides that, SearchWP is designed to overcome the limitations of default search and index everything that matters on your website. This includes custom fields, categories, tags, product details, media files, and more.
First, you’ll need to visit the SearchWP website and create a new account.
Once you’ve signed up, the next step is to is download the SearchWP plugin.
To do that, simply go to your account area and switch to the ‘Downloads’ tab. From here, you can click the Download SearchWP button and save the plugin file to your computer.
From here, you can install and activate the SearchWP plugin on your site.
If you need help with this, then please see this guide on how to install the WordPress plugin.
After you’ve activated the plugin, you’ll see the SearchWP onboarding wizard. Simply click the ‘Start Onboarding Wizard’ button and follow the onscreen instructions to configure the plugin.
Next, you will need to install an extension to make form submissions searchable in WordPress. For this tutorial, we’ll use the WPForms extension and make our event submission form entries searchable.
You can simply head to SearchWP » Extensions from the WordPress admin panel and navigate to Source – WPForms extension. From here, go ahead and click the ‘Install’ button.
You should see that the extension will now automatically install and activate, with the Status changing from Not Installed to Active.
Customize Search Engine to Include Form Submissions
Now that you’ve set up SearchWP on your site and added the WPForms extension, the next step is to customize the search engine settings to make form submissions searchable.
First, you’ll need to head to the SearchWP » Algorithm page from your WordPress dashboard and add a new engine. Simply click the ‘Add New’ button to continue.
Next, a new window will open with your Supplemental engine. Here, you can select the sources for your new search engine.
By default, SearchWP will include Posts, Pages, Users, and Media along with all the forms you have created in WPForms as sources.
To limit the search to only WPForms, you can uncheck all other sources except the forms. If you need to make only a specific form searchable, then you can simply select that particular form.
For example, we’ll only select the Event Submission Form as a source for this tutorial. This way, users can easily search for different events that are submitted through the form.
You can also change the name of the new engine from Supplemental to anything you like under the ‘Engine Label’ field. For example, we’ll name our new engine as ‘WPForms Engine.’
When you’re finished, click the ‘Done’ button.
Next, you’ll see each form as a source in the engine. You can then select which form fields you’d want to use as attributes.
Attributes are fields you want to search for a given source. To edit them, simply click the ‘Add/Remove Attributes’ button.
Next, a small window will open where you can select which attributes to use.
Simply uncheck the form fields you don’t want the source to search.
After choosing the attributes, simply click the ‘Done’ button.
You can also move the slider to adjust the relevance weights. The further to the right the slider is set for an attribute, the more influence that attribute has on the position in the search results.
Next, you will need to scroll to the top and click the Save button to store your changes.
You’ve now successfully created a new search engine that search form submissions.
Displaying Form Entries as Search Results
Now that you’ve created a search engine that looks for form submissions, the next step is to display the WPForms entries in the search results.
Note: An important thing to remember is that you’ll need development skills or need to hire a developer to implement the code on your site. This way, your form entries will appear as search results using SearchWP.
First, you’ll need to set up a search form for the Supplemental Engine you created earlier. Start by creating an <input> with a different name than s, as that name will trigger a native WordPress search.
You can start with the following code:
<form role="search" method="get" class="search-form"
action="<?php echo site_url( 'search-results/' ); ?>">
<label>
<span class="screen-reader-text">
<?php echo _x( 'Search for:', 'label' ) ?>
</span>
<input type="search" class="search-field"
name="searchwp"
placeholder="<?php echo esc_attr_x( 'Search...', 'placeholder' ) ?>"
value="<?php echo isset( $_GET['searchwp'] ) ? esc_attr( $_GET['searchwp'] ) : '' ?>"
title="<?php echo esc_attr_x( 'Search for:', 'label' ) ?>" />
</label>
<input type="submit" class="search-submit"
value="<?php echo esc_attr_x( 'Search', 'submit button' ) ?>" />
</form>
There are two things to note about this snippet:
- The <input> name used is searchwp
- The form action is pointing to site_url( ‘search-results/’ ). That means that if your site URL is example.com this form will redirect to example.com/search-results/ upon submission. This guide assumes the URL points to a Page you have created for the purpose of displaying Supplemental Engine results.
When you create your search form, it has an action that points to a URL designated as the Page to display your results. To pull in results from SearchWP, you will first need to create a custom Page Template.
For more details regarding the search form code and page template, please refer to our Supplemental Engine documentation.
Here’s a starter template you can work with, it’s based on the code shown in our Supplemental Engine documentation:
<?php
/* Template Name: SearchWP Results */
global $post;
// Retrieve applicable query parameters.
$search_query = isset( $_GET['searchwp'] ) ? sanitize_text_field( $_GET['searchwp'] ) : null;
$search_page = isset( $_GET['swppg'] ) ? absint( $_GET['swppg'] ) : 1;
// Perform the search.
$search_results = [];
$search_pagination = '';
if ( ! empty( $search_query ) && class_exists( '\\SearchWP\\Query' ) ) {
$searchwp_query = new \SearchWP\Query( $search_query, [
'engine' => 'wpformsengine', // The Engine name.
'fields' => 'all', // Load proper native objects of each result.
'page' => $search_page,
] );
$search_results = $searchwp_query->get_results();
$search_pagination = paginate_links( array(
'format' => '?swppg=%#%',
'current' => $search_page,
'total' => $searchwp_query->max_num_pages,
) );
}
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<header class="page-header">
<h1 class="page-title">
<?php if ( ! empty( $search_query ) ) : ?>
<?php printf( __( 'Search Results for: %s' ), esc_html( $search_query ) ); ?>
<?php else : ?>
SearchWP Supplemental Search
<?php endif; ?>
</h1>
<!-- BEGIN Supplemental Engine Search form -->
<form role="search" method="get" class="search-form"
action="<?php echo site_url( 'search-results/' ); ?>">
<label>
<span class="screen-reader-text">
<?php echo _x( 'Search for:', 'label' ) ?>
</span>
<input type="search" class="search-field"
name="searchwp"
placeholder="<?php echo esc_attr_x( 'Search...', 'placeholder' ) ?>"
value="<?php echo isset( $_GET['searchwp'] ) ? esc_attr( $_GET['searchwp'] ) : '' ?>"
title="<?php echo esc_attr_x( 'Search for:', 'label' ) ?>" />
</label>
<input type="submit" class="search-submit"
value="<?php echo esc_attr_x( 'Search', 'submit button' ) ?>" />
</form>
<!-- END Supplemental Engine Search form -->
</header>
<?php if ( ! empty( $search_query ) && ! empty( $search_results ) ) : ?>
<?php foreach ( $search_results as $search_result ) : ?>
<article class="page hentry search-result">
<?php
switch( get_class( $search_result ) ) {
case 'SearchWP\Sources\WPForms\Entry':
$form_id = $search_result->form_id;
$entry_id = $search_result->entry_id;
// NOTE: WPForms Field values are stored in the entry fields property as an array.
// Each field has the array key equal to the order they were added to the form editor.
$fields = $search_result->fields;
?>
<div class="result">
Form ID: <?php echo esc_html( $form_id ); ?><br>
Entry ID: <?php echo esc_html( $entry_id ); ?><br>
Name: <?php echo esc_html( $fields[0]['value'] ); ?><br>
Email: <?php echo esc_html( $fields[1]['value'] ); ?><br>
Subject: <?php echo esc_html( $fields[5]['value'] ); ?><br>
Comment: <?php echo esc_html( $fields[2]['value'] ); ?><br>
</div>
<?php
break;
}
?>
</article>
<?php endforeach; ?>
<?php if ( $searchwp_query->max_num_pages > 1 ) : ?>
<div class="navigation pagination" role="navigation">
<h2 class="screen-reader-text">Results navigation</h2>
<div class="nav-links"><?php echo wp_kses_post( $search_pagination ); ?></div>
</div>
<?php endif; ?>
<?php elseif ( ! empty( $search_query ) ) : ?>
<p>No results found, please search again.</p>
<?php endif; ?>
</main> <!-- .site-main -->
</div> <!-- .content-area -->
<?php get_footer(); ?>
Next, the above code for the supplemental engine page template needs to be adapted for WPForms entries.
Here’s the code for WPForms that you can use:
<?php
$searchwp = new \SearchWP\Query( 'marketing', [
'engine' => 'wpforms',
'fields' => 'all',
] );
foreach ( $searchwp->results as $result ) {
switch ( get_class( $result ) ) {
case 'SearchWP\Sources\WPForms\Entry':
$form_id = $search_result->form_id;
$entry_id = $search_result->entry_id;
// NOTE: WPForms Field values are stored in the entry fields property as an array.
// Each field has the array key equal to the order they were added to the form editor.
$fields = $search_result->fields;
?>
<div class="result">
Form ID: <?php echo esc_html( $form_id ); ?><br>
Entry ID: <?php echo esc_html( $entry_id ); ?><br>
Name: <?php echo esc_html( $fields[0]['value'] ); ?><br>
Email: <?php echo esc_html( $fields[1]['value'] ); ?><br>
Subject: <?php echo esc_html( $fields[5]['value'] ); ?><br>
Comment: <?php echo esc_html( $fields[2]['value'] ); ?><br>
</div>
<?php
break;
default:
// Another Source was added to the SearchWP Engine.
print_r( $result );
}
}
In the code snippet, make sure to replace wpforms with your engine’s name in this part: ‘engine’ => ‘wpforms’,
You can find the name of your new engine on the SearchWP » Algorithm page. For instance, we’ll replace wpforms with wpformsengine in the code snippet.
To learn more about displaying WPForms entries as results, please refer to our WPForms documentation.
Lastly, if you require any further assistance, then our team is always here to help. Simply reach out to our support team and we’ll be happy to help!
We hope this article helped you learn how to include WordPress form submission in search results. You may also want to see our guides on how to add Meta Box fields to WordPress search and how to track your WordPress site search activity.
Ready to create a better and more personalized WordPress search experience? Get started with SearchWP today!