• mstudioIL

    (@mstudioil)


    My client said the countries’ order is not in alphabetical order, is there is option to fix this?

Viewing 9 replies - 1 through 9 (of 9 total)
  • kraeMit

    (@kraemit)

    Double post.

    Did you check this informations?
    –> https://www.ads-software.com/support/topic/sorting-the-list/

    As this names will not change: A fast and easy fix would be to copy the names and create a list yourself.
    You can copy it from here : https://contactform7.com/listo/

    • This reply was modified 4 years ago by kraeMit.
    • This reply was modified 4 years ago by kraeMit.
    Thread Starter mstudioIL

    (@mstudioil)

    I would prefer answer from the creator

    kraeMit

    (@kraemit)

    Sure you want. ??

    Thread Starter mstudioIL

    (@mstudioil)

    I don’t want long list, the idea of the plugin is to avoid long list

    Plugin Contributor Yordan Soares

    (@yordansoares)

    Hello @mstudioil,

    You can sort the countries alphabetically this way:

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

    Best regards,
    Yordan.

    ++1 : -)

    Regards
    kraeMit

    Thread Starter mstudioIL

    (@mstudioil)

    Thanks, @yordansoares
    I don’t understand why the list is not sorted from the begin

    I’ve used this on my website, skips the first entry (contains “Select” text). Change the ID (i.e. ‘#country’) as needed.

    // Country sorting function
    
    if (jQuery('.wpcf7-form').length) {
    	var options = jQuery('option:gt(1)', '#country'),
    		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);
    	});
    }

    Ideally, this would be included in the plugin – visible name sorting is more logical than the ISO sorting.

    Thanks for sharing this!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Order of countries with Listo’ is closed to new replies.