Support » Plugin: Gravity Forms + Custom Post Types » [Plugin: Gravity Forms Custom Post Types] Dropdown populated with custom post type from within cus

  • Hi,

    First of all thanks for the amazing plugin – it has made using Gravity Forms for the site I’m creating a breeze!

    I’m already using the beta of this plugin, but I am stuck trying to work out a problem. I’m trying to create a dropdown populated with all the custom posts that have a certain term in a custom taxonomy.

    I know I can create a drop-downs that are populated with taxonomies which from which I can exclude certain terms, but I’m stuck with this problem…

    Anyone got any ideas on how to do this?


Viewing 1 replies (of 1 total)
  • I couldn’t work out how to do the above with this plugin, but it was simple enough to write as a function declared in my functions.php file

    add_filter("gform_pre_render", "populate_producers_dropdown");
    //Note: when changing drop down values, we also need to use the gform_admin_pre_render so that the right values are displayed when editing the entry.
    add_filter("gform_admin_pre_render", "populate_producers_dropdown");
    function populate_producers_dropdown($form){
    //only populating drop down for form id 3
    if($form["id"] != 3)
    return $form;
    //Reading posts for custom post type "place" with custom taxonomy "placecategory" and term "producer";
    $args = array(
        'orderby'         => 'title',
        'order'           => 'ASC',
        'post_type'       => 'place',
    	'taxonomy' 	=> 'placecategory',
    	'term' => 'producers'
    $posts = get_posts($args);
    //Creating drop down item array.
    $items = array();
    //Adding initial blank value.
    $items[] = array("text" => "", "value" => "");
    //Adding post titles to the items array
    foreach($posts as $post)
    $items[] = array("value" => $post->ID, "text" => $post->post_title);
    //Adding items to field id 9. Replace 9 with your actual field id. You can get the field id by looking at the input name in the markup.
    foreach($form["fields"] as &$field)
    if($field["id"] == 9){
    $field["choices"] = $items;
    return $form;
Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: Gravity Forms Custom Post Types] Dropdown populated with custom post type from within cus’ is closed to new replies.