Add Fields to Pulldown Lists in Gravity Form Dynamic Population from Pods Feed

Modify what is displayed in the pulldown lists for the dynamic lists using the Pods Gravity Forms Add-on

This filter lets you update the gravity form pulldown lists. For example, you can use it to dynamically filter the choice list (e.g., based on a field value) or you can change the labels on the choice items.

Here’s an example for updating the choice list for form 7, field 21:

<?php
add_filter( 'pods_gf_dynamic_choices_7_21', 'bike_tour_choices' );

/**
 * Filter the list of choices for a Gravity Form field.
 *
 * @param array $choices List of choices.
 *
 * @return array List of choices.
 */
function bike_tour_choices( $choices ) {
	$pod_name = 'tour';

	$active = 1;

	// Get the value from the user meta.
	$entry_id = get_user_meta( get_current_user_id(), 'search_tours_entry_id', true );

	if ( $entry_id ) {
		$entry = GFAPI::get_entry( $entry_id );

		// Get field 3 value from the GF entry.
		if ( 'Active' !== rgar( $entry, 3 ) ) {
			$active = 0;
		}
	}

	$new_choices = array();

	// Add "-- Select One --" as the first entry in the choices array.
	$new_choices[] = array(
		'text'  => '-- Select One --',
		'value' => '-- Select One --',
	);

	$pod = pods( $pod_name );

	foreach ( $choices as $choice ) {
		// Ignore -- Select One --
		if ( ! is_numeric( $choice['value'] ) ) {
			continue;
		}

		// Fetch the item from the value (assuming it's an ID).
		$pod->fetch( $choice['value'] );

		// Skip this choice if the item does not exist.
		if ( ! $pod->exists() ) {
			continue;
		}

		// Depending on the user's related entry, only show the active or inactive tours.
		if ( (int) $pod->field( 'active' ) === $active ) {
			// Add the tour number field before the choice text.
			$text = $pod->field( 'tour_number' ) . ' ' . $choice['text'];

			$new_choices[] = array(
				'text'  => $text,
				'value' => $choice['value'],
			);
		}
	}

	return $new_choices;
}

This changes the default pulldown list from the post title like this:

 

To this instead:

 

Submitted through forum post from joneisman

Notes on Usage of the Filter

You can use the pods_gf_dynamic_choices_form_field filter to modify this set of choices. If you needed to modify the filter based on the selection of another field, you can use existing Gravity Forms filters to call this filter based on selections or entries in those fields. You should look into this document at Gravity Forms Documentation on Dynamically Populating selection fields as there are multiple filters that must be modified to dynamically change multiple fields based on other field choices.

Questions