Support » Plugin: Pods - Custom Content Types and Fields » document the pods_gf_dynamic_choices filter

  • Resolved joneiseman



    I found the pods_gf_dynamic_choices filter but it took me a long time to discover it. 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:

    add_filter( 'pods_gf_dynamic_choices_7_21', 'bike_tour_choices' );
    function bike_tour_choices($choices)
        $active = 1;
        /* pick up a value from a different GF form entry
        $entryid = get_user_meta(get_current_user_id(), 'search_tours_entry_id', true);
        if ($entryid) {
            $entry = GFAPI::get_entry($entryid);
            /* get field 3 value from the GF entry
            if (rgar($entry, 3) != 'Active')
    	    $active = 0;
        $choice_array = array();
        foreach ($choices as $choice) {
    	if (is_numeric($choice['value'])) { // ignore -- Select One --
                $tpod = pods('tour', $choice['value']);
                // pick either all active tours or all inactive tours
                // depending on the value of $active
    	    if ($tpod->field('active') == $active)
    	        $choice_array[] = array('tourno' => $tpod->field('tour_number'),
                                   'title' => $choice['text'],
                                   'ID' => $choice['value']);
    	$choices = array();
            // add "-- Select One --" as the first entry in the choices array
    	$choices[] = array('text' => '-- Select One --',
                               'value' => '-- Select One --');
    	foreach ($choice_array as $choice) {
    	    $text = $choice['tourno'] . ' ' . $choice['title'];
                $choices[] = array('text' => $text, 'value' => $choice['ID']);
    	return $choices;

    This is a really powerful filter. I think this is something people will commonly want to do when integrating Pods with Gravity Forms.
    Is it possible to add this to the documentation? I wasn’t able to find anything with a Google search (but at least people will now be able to find this post).

    • This topic was modified 9 months, 3 weeks ago by joneiseman.
Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Jim True


    You do know about the Pods Gravity Forms Add-on, right? That’s exactly what it’s designed to do.

    We can add this to the Code Snippets on our new Docs website, but the Dynamically Populated drop-down from Taxonomy or Relationship is built into the add-on above.

    I am using the Pods Gravity Forms Add-on. It says the following when enabling the Dynamically Populated option for a relationship field.

    Incoming Field Data
    Check this option to enable data to be passed to the form and pre-populate this field dynamically. Data can be passed via Query Strings, Shortcode and/or Hooks.

    I can then specify a parameter name for this field. What hook would I use to populate the values in the pulldown list (based on this parameter name)?

    I want to populate the labels for the pulldown items with custom values, not just the title of the related pod item.

    By the way, the filter I’m documenting is part of the Gravity Forms add-on.

    • This reply was modified 9 months, 3 weeks ago by joneiseman.
    • This reply was modified 9 months, 3 weeks ago by joneiseman.
    • This reply was modified 9 months, 3 weeks ago by joneiseman.
    Plugin Author Jim True


    Okay, I wasn’t aware that’s what you were doing (using a different field in the choice list through the population). We do only provide by default what most people need (ie the same field we show by default on the back-end).

    If you want to provide a couple of screen shots/examples, I can drop this on our new docs site at in the Code Snippets section and connect it to the Gravity Forms stuff.

    Here’s what the default pulldown looks like:

    Each entry just has the post title.

    After my modification it now has the “tour number” and the title.

    Plugin Author Jim True


    Gotcha, that makes sense, so you’re just using that filter to change the option ‘label’ but not the value, so it still works the way it’s supposed to work.

    Are you okay if we put both your screen shots and your code snippet on our website? I can reference and add a linkback to your website.

    BTW, you can also join our Slack Chat at and we can chat about stuff like this 😉

    Yes, it’s fine to put the code snippet and the screenshots on your website. It’s a “members only” website so you can’t really link back to my website.


    Plugin Author Jim True


    Okeydoke, I’ll link out to your profile unless there’s another place you’d prefer 😉

    That’s fine.

    Plugin Author Jim True


    Looks Great!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘document the pods_gf_dynamic_choices filter’ is closed to new replies.