PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Alphabetise Category Drop Downs

  1. Hi

    With reference to this post http://www.gravityhelp.com/forums/topic/alphabetize-category-drop-down

    I have a category drop down of US states that is a sub-category and they do not order by name, if you check out http://rockclimbs.org/add-a-climb you can see that they are in date creation order/

    I'm using GF version 1.6.4.5.4

    Posted 6 years ago on Tuesday July 10, 2012 | Permalink
  2. David Peralty
    Administrator

    Can you show the code you used to populate this field?

    Posted 6 years ago on Tuesday July 10, 2012 | Permalink
  3. see screen dump, its a standard form to post category list

    http://screencast.com/t/BG4QeHuqzLI

    Posted 6 years ago on Tuesday July 10, 2012 | Permalink
  4. David Peralty
    Administrator

    Thanks, I'll try to replicate and see what I can come up with. It should auto-sort by alphabetical. These aren't custom taxonomies or anything, correct, just regular WordPress categories?

    Posted 6 years ago on Tuesday July 10, 2012 | Permalink
  5. Just regular WP categories, the only weird thing is some of the categories may be empty, and there are loads - all the us states

    Posted 6 years ago on Tuesday July 10, 2012 | Permalink
  6. Were you able to re-create the issue?

    Posted 6 years ago on Wednesday July 11, 2012 | Permalink
  7. Any updates on this?

    Posted 6 years ago on Monday July 16, 2012 | Permalink
  8. David Peralty
    Administrator

    Hi wpdude - sorry about the delay. I've tried on my three test environments using various category set-ups, including trying to replicate yours as well as your issue, and have been unable to. Can you send me an admin login so I can take a look into this? My e-mail is peralty@rocketgenius.com and please including a link back to this thread.

    Posted 6 years ago on Monday July 16, 2012 | Permalink
  9. I sent the login details, any update, do you need me to send them again?

    Posted 6 years ago on Tuesday August 7, 2012 | Permalink
  10. Any news from this thread, I can resend the details if required

    Posted 6 years ago on Wednesday August 15, 2012 | Permalink
  11. I did not receive the login information from Dave, but I was trying to recreate this myself and could not. You said "you can see that they are in date creation order" - I did not see a reference to the date created in the wp_term, wp_term_taxonomy or wp_term_relationships tables. Do you mean they are sorted by category ID (which should be the same order as creation date)?

    Here is a screenshot of my child category drop down:
    http://minus.com/lmljbceBJMaQY

    Here is the listing of these categories from wp_terms table, ordered alphabetically: http://minus.com/l17JQ2DvRIaox

    You can see that the drop down is not sorted by ID in my form but by name ASC.

    Does your category drop down appear in the correct order in the form preview, or is it wrong there are well? If the drop down is in the correct order in the form preview, it's likely a plugin conflict. Also, are you using the most recent versions of WordPress (I see that you are, for Gravity Forms)?

    Posted 6 years ago on Wednesday August 15, 2012 | Permalink
  12. I've got the same problem and my select options get generated as follows:

    <select name='input_2' id='input_1_2' class='medium gfield_select' tabindex='2' >
    <option value='246' >GBPUSD</option>
    <option value='517' >Analysis</option>
    <option value='314' >AUDUSD</option>
    <option value='313' >NZDUSD</option>
    [...]

    I am also looking for a way to order these in alphabetical order as currently the order appears to be fairly random.

    Can you have another look into this for us please?

    Cheers

    Posted 6 years ago on Friday September 7, 2012 | Permalink
  13. ysan
    Member

    Hi Gravity Support,

    I have a similar issue. In my installation I have a parent category 'number of participants' and child categories 10, 20, 30,... until 200.

    It would be nice to see those categories in a logical order such as :

    Number of Participants
    - 10
    - 20
    - 30
    - ...
    - 200

    Instead Gravity forms returns :

    Number of Participants
    — 10
    — 100
    — 120
    — 140
    — 160
    — 180
    — 20
    — 200
    — 30
    — 40
    — 50
    — 60
    — 70
    — 80
    — 90

    Is there a possibility to force GF to order those categories by category ID?

    Is it a GF issue or a more general WP issue? I see that the categories in WP (new post, add categories) also are ordered in the second way (10, 100, 120, 140,... 20).

    Thank you for your input and help!

    Y

    Posted 5 years ago on Friday July 5, 2013 | Permalink
  14. David Peralty
    Administrator

    As far as I know, WordPress sorts them by slug, and treats them as text, so if your slugs are those numbers, and it is treating them like text, then to WordPress, it is sorting them correctly. I am not entirely sure how to change this, but I'll send a note to our developers.

    Posted 5 years ago on Friday July 5, 2013 | Permalink
  15. ysan
    Member

    Hi David,

    I have changed the slugs into an alphabetical order

    category "10" gets slug "a-10", "20" gets slug "b-20" and so on. But it did not change the order of the categories.

    Hope you and your developers can find a solution.

    KR

    Ysan

    Posted 5 years ago on Friday July 5, 2013 | Permalink
  16. ysan
    Member

    Hi David,

    as mentioned before, changing the slug in something "alphabetical" did not work in order to arrange the categories on the admin side alphabetically. However this code does

    add_filter( 'get_terms_args', 'wpse_53094_sort_get_terms_args', 10, 2 );
    function wpse_53094_sort_get_terms_args( $args, $taxonomies )
    {
        global $pagenow;
        if( !is_admin() || ('post.php' != $pagenow && 'post-new.php' != $pagenow) )
            return $args;
    
        $args['orderby'] = 'slug';
        $args['order'] = 'DESC';
    
        return $args;
    }

    as found on this website : http://wordpress.stackexchange.com/questions/53094/how-to-change-the-categories-order-in-the-admin-dashboard

    I was hoping that Gravity Forms copies the way Wordpress orders the categories; but no luck so far...

    Have a nice weekend

    Posted 5 years ago on Saturday July 6, 2013 | Permalink
  17. Thanks for the suggestion. We will be looking at what it takes to sort categories alphabetically in a future version.

    Posted 5 years ago on Monday July 8, 2013 | Permalink
  18. ysan
    Member

    Can you inform me how the categories are ordered now in GF? I might make some changes. I have tried to change the slug - no results however. The categories are also not ordered by cat ID. So by what parameter are they?

    Posted 5 years ago on Monday July 8, 2013 | Permalink
  19. To make sure I answer your question correctly, let me ask you a couple of questions.
    1- Where do you need the categories to be sorted? WP dashboard in the form editor, or on the front end of your website (the actual form)
    2- If the answer to the first question is on the front end, are you displaying all categories or a selected few categories? Also, which field type are you using to display these categories? (i.e. drop down, radio button, etc...)

    Posted 5 years ago on Monday July 8, 2013 | Permalink
  20. ysan
    Member

    Hi Alex,

    The categories need to be sorted on the actual form. So I have a form with a "post field - category" and I would like to show the number of participants with checkboxes.

    The parent category is "number of participants"
    Child categories are 10, 20, 30, ... until 200

    As an answer on your question n° 2 : only a selected few categories (the child categories of "number of participants"

    This is how it looks on the site http://minus.com/lfyBypbVqwal4

    And this is how I would like them to see :

    Number of Participants
    - 10
    - 20
    - 30
    - ...
    - 200

    It is not clear to me how the categories are now sorted in the form (on the actual website).

    I have tried several things to get them in a numerical order
    - make the slug alphabetical (a10, b20, and so on)
    - leading zero in category name (010, 020, and so on)
    - changing the way wordpress sorts the categories.

    A solution for me could be to force GF to use the slugs for ordering the categories. Ordering by cat ID is also a good (perhaps better) solution.

    Posted 5 years ago on Tuesday July 9, 2013 | Permalink
  21. What you will need to do is use the gform_pre_render hook to sort the field choices (which contains the categories). The following code snippet should do the trick:

    //NOTE: replace 9 below (int gform_pre_render_9) with your actual form ID
    add_filter("gform_pre_render_9", "sort_categories");
    
    function sort_categories($form){
    
        foreach($form["fields"] as &$field){
    
            //NOTE: replace 2 below (in $field["id"] == 2) with your category field ID
            if($field["id"] == 2)
                usort($field["choices"], "sort_numerically");
        }
    
        return $form;
    }
    
    function sort_numerically($a, $b){
        return floatval($a["text"]) > floatval($b["text"]);
    }
    Posted 5 years ago on Wednesday July 10, 2013 | Permalink
  22. ysan
    Member

    Hi Alex,

    You cannot imagine how happy I am. Really thank you!

    Can you take a look for another small change?

    In the same form ID, there are several category fields IDs I would like to sort numerically.

    In my example :

    Form ID : 2

    Field ID's : 34 and 38

    Again, thank you very much for this great support!

    KR

    Y

    Posted 5 years ago on Wednesday July 10, 2013 | Permalink
  23. Richard Vav
    Administrator

    Handling via new support form.

    Posted 5 years ago on Monday July 15, 2013 | Permalink

This topic has been resolved and has been closed to new replies.