Search code examples
phpwordpressgravity-forms-plugin

Filter Gravity Forms Entries by field value


I am trying to echo out a list of Gravity Forms Entries, but only want to echo out the entries that have a certain value, within a certain field.

So for example, $entry['53'] is a field within the form that allows the user to select from a dropdown. There are only two options. Let's say A and B. How would I go about altering my code below to only show entries that have a value of B ?

The code I have at the moment is:

<?php
      //Get the Form ID to get the entries from and store it within a varibale

      $search_criteria = null;
        $sorting = null;
        $paging = null;

        $entries = GFAPI::get_entries( $form_id, $search_criteria, $sorting, $paging );

        echo '<ul>';
            foreach($entries as $entry) :
                echo '<li>Title: ' . $entry['2'] . '</li>';
            endforeach;
        echo '</ul>';
  ?>

Many Thanks


Solution

  • Try this:

    $search_criteria = array(
            'status'        => 'active',
            'field_filters' => array(
                array(
                    'key'   => '53',
                    'value' => 'B',
                ),
            )
        );