Problem order_by “name”
-
I was with the problem that some of them reported here in alphabetical order, and as I searched a lot and did not find any answers, I decided to solve the problem without entering the PHP code of the plugin, to be free for a future update.
It was no use for the code below, both selects were loaded out of order
<?php echo do_shortcode( ‘[searchandfilter taxonomies=”category,post_tag,search” types=”select,select,” order_by=”name,name,” order_dir=”ASC,ASC,”]’ ); ?>
What I did was a js code (depends on jquery) that solves the case of alphabetical ordering.
In my case I order categories and tags and this single code solves both at the same time.
I hope it helps.
<script>
jQuery(document).ready(function() {
jQuery(‘form.searchandfilter select’).each(function(){
var options = jQuery(this).find(‘option’);
var arr = options.map(function(_, o) {
return {
t: jQuery(o).text(),
v: o.value,
s: jQuery(o).attr(‘selected’)
};
}).get();
arr.sort(function(o1, o2) {
if(o1.v > 0) {
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);
jQuery(o).attr(‘selected’, arr[i].s);
});
});
});</script>
The topic ‘Problem order_by “name”’ is closed to new replies.