Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Last active July 27, 2020 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jchristopher/7c908aa998e63e2c72648a1a2102b0e7 to your computer and use it in GitHub Desktop.
Save jchristopher/7c908aa998e63e2c72648a1a2102b0e7 to your computer and use it in GitHub Desktop.
Outputting SearchWP results that are Gravity Forms Entries
<?php
$searchwp = new \SearchWP\Query( 'marketing', [
'engine' => 'gravity',
'fields' => 'all',
] );
foreach ( $searchwp->results as $result ) {
switch ( get_class( $result ) ) {
case 'SearchWP\Sources\GravityForms\Entry':
// NOTE: Gravity Forms Field values are keyed by the Field ID in the Form editor.
?>
<div class="result">
Form ID: <?php echo esc_html( $result->id ); ?><br>
Name: <?php echo esc_html( $result->{'1'} ); ?><br>
Email: <?php echo esc_html( $result->{'2'} ); ?><br>
Type: <?php echo esc_html( $result->{'3'} ); ?><br>
Feature: <?php echo esc_html( $result->{'4'} ); ?>
</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