Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Takayuki Miyoshi

    (@takayukister)

    No, there isn’t.

    But if you are familiar with WordPress filters and actions, it’s easy to reorder the output using the wpcf7_form_tag_data_option filter hook in contact-form-7/modules/listo.php file.

    Hi Takayuki Miyoshi

    Thanks for this great plugin!

    could you write to use more how to order as ABC ?

    There is several theads about this. i open the file which you said and find the line wpcf7_form_tag_data_option and its
    add_filter( 'wpcf7_form_tag_data_option', 'wpcf7_listo', 10, 3 );

    so what i have to change here to get ABC ordering ?

    Many many thanks!

    Hi there,

    Any update on this? I am also looking for a solution to sort the list in alphabetical order.

    • This reply was modified 8 years, 2 months ago by designgr82.

    In case @designgr82 or anybody else is still looking for a solution to this, here is the code to add to your function.php in order to sort the list :

    function wpcf7_listo_ordered( $data) {
    	sort($data);
    	return $data;
    }
    add_filter( 'wpcf7_form_tag_data_option', 'wpcf7_listo_ordered', 11, 1 );

    Thnank you WordPressfab
    I tried your code above but i get this error…

    Warning: sort() expects parameter 1 to be array, null given in /home/tdlevent/public_html/wp-content/themes/tdlevents/functions.php on line 15

    Hello, any help? Please… thank you!

    If anyone is still looking for an answer, my solution is to use jquery to sort the country list. Below is the sorting code:

    var options = jQuery(‘select[name=country] option’); // change this to your identifier
    var arr = options.map(function(_, o) { return { t: jQuery(o).text(), v: o.value }; }).get();
    arr.sort(function(o1, o2) { return o1.t > o2.t ? 1 : o1.t < o2.t ? -1 : 0; });
    options.each(function(i, o) {
    o.value = arr[i].v;
    jQuery(o).text(arr[i].t);
    });

    Hope this helps!

    @wordpressfab : thanks for your code to sort Listo in alphabetical order, it works for me.
    Just one thing: this sorting function is OK for ASCII characters (US), but in some other languages, countries beginning with non ASCII characters (é è ? ?…) are listed at the end, after XYZ. So how to handle those characters in alphabetical order?
    I tried to add the PHP setlocale function to your code but have not enough skills to achieve this.
    Thanks for your help!

    I finally found a way to sort the countries list including non ASCII characters (french in my case).
    It’s based on @wordpressfab code and added in function.php:

    function wpcf7_listo_ordered( $data) {
    	setlocale(LC_ALL, 'fr_FR.utf8');
    	sort($data, SORT_LOCALE_STRING);
    	return $data;
    }
    add_filter( 'wpcf7_form_tag_data_option', 'wpcf7_listo_ordered', 11, 1 );

    A setlocale PHP function is added with specific language to treat : fr_FR.utf8 for french.
    And SORT_LOCALE_STRING parameter added to sort function to handle language specific characters.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Sorting the list’ is closed to new replies.