Gravity Forms + Custom Post Types
Reorder a Drop Down Populated with a Custom Post Type (4 posts)

  1. fettabachi
    Posted 3 years ago #

    I tried to reorder the drop down fields but after saving my form they revert to the default order which is id# descending.

    How can I control the ordering?


    How can I change the value?



  2. mealtime
    Posted 2 years ago #

    Would also like to find this out as the same problem occurs with taxonomies. If you uncheck populate with a taxonomy or post types, the order will be saved, but once you check it off again, the order diverts back to being alphabetical.

  3. fettabachi
    Posted 2 years ago #

    I used this in my functions file instead;

    // Add Camp Sessions to Gravity Form select list
    add_filter("gform_pre_render", "populate_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_dropdown");
    function populate_dropdown($form){
        //only populating drop down for form id 1
        if($form["id"] != 1)
           return $form;
        //Reading posts for the Camp Sessions post type;
            $args = array(
               'posts_per_page' => -1,
               'post_type'      => 'camp_sessions',
               'post_status'    => 'publish',
               'orderby'        => 'title',
               'order'          => 'ASC',
            $posts = get_posts ( $args );
        //Creating drop down item array.
        $items = array();
        //Adding initial value.
        $items[] = array("text" => "Please select a session", "value" => "");
        //Adding post titles to the items array
        foreach($posts as $post)
            $items[] = array("value" => $post->post_title, "text" => $post->post_title);
        //Adding items to field id 14. You can get the field id by looking at the field name on the form.
        foreach($form["fields"] as &$field)
            if($field["id"] == 14){
                $field["choices"] = $items;
        return $form;
  4. mealtime
    Posted 2 years ago #

    Thanks! Will test it out :-)

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Gravity Forms + Custom Post Types
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic