Skip to content

Instantly share code, notes, and snippets.

@searchwpgists
Last active October 3, 2024 15:52
Show Gist options
  • Save searchwpgists/f298042908b9bd501cac1ad84815c254 to your computer and use it in GitHub Desktop.
Save searchwpgists/f298042908b9bd501cac1ad84815c254 to your computer and use it in GitHub Desktop.
Outputting SearchWP results that are WPForms Entries
<?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 );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment