Source – WPForms

Current version: 1.0.0 View Changelog

Download available with active license

Table of Contents

WPForms logo

WPForms is the leading drag-and-drop form builder plugin for WordPress. It’s widely recognized for its user-friendly interface and powerful capabilities. This Extension enables you to utilize WPForms entries as a custom Source for SearchWP, making it possible to search WPForms entries with SearchWP!

Adding WPForms Entries to SearchWP’s Index

Once the SearchWP Source – WPForms extension has been installed and activated, your forms by WPForms will appear in the Sources list for your SearchWP Engine.

Note: This custom Source can be used only with a Supplemental Engine.

Let’s say you were building a Suggestion request area on your website and using WPForms Suggestion Form to collect entries.

Screenshot of WPForms setup

You could utilize SearchWP to allow customers to first search existing entries before submitting their own, so they could join in up-voting the existing submission instead of creating a duplicate.

The first step would be to create a new Supplemental Engine that has our Suggestion Form as the Source:

Adding WPForm to SearchWP

Please note that you can add multiple forms by WPForms to the same engine if you want.

Once the form has been added to the SearchWP engine, all the searchable form fields are added as attribute to the engine source. You can click on Add/Remove Attributes to change the list of fields you want to search.

Displaying WPForms Entries as Results

The SearchWP Source – WPForms Extension will make available WPForms Entries as search results. This integrates as any Source would when working with a Supplemental Engine.

Unlike a native WordPress search that has The Loop which is an array of WP_Post objects that WordPress’ API interacts with, the results set for a Supplemental Engine can be made up of any SearchWP Source object.

WPForms uses a stdClass for Form Entries. As a convenience, SearchWP Source – WPForms will return results in a wrapper object:

\SearchWP\Sources\WPForms\Entry

This will help as you iterate over your results array:

<?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 );
}
}
view raw page.php hosted with ❤ by GitHub

Note: You can prevent SearchWP from wrapping results in the class and return instead a stdClass with the following hook:

<?php
add_filter( 'searchwp\source\wpforms\entry\raw', '__return_true' );

SearchWP Source – WPForms allows you to make any WPForms Entry searchable using SearchWP! You can make as many SearchWP Engines with as many WPForms Sources as you’d like, each with their own configuration of Fields. Use SearchWP’s capable search algorithm to make your WPForms Entries searchable!

Changelog

1.0.0

  • Initial Release.

Create a Better WordPress Search Experience Today

Never lose visitors to unhelpful search results again. SearchWP makes creating your own smart WordPress search fast and easy.

Get SearchWP Now
Multiple Search Engines Icon