Hi! Thanks for your help. I’ve made it!
Here is solution – not perfect one, but works:
Adding code to function.php of template width sorting by terms (category) as you’ve mentioned:
// custom sorting
add_filter( 'wpsl_store_meta', 'custom_store_meta', 10, 2 );
function custom_store_meta( $store_meta, $store_id ) {
$terms = wp_get_post_terms( $store_id, 'wpsl_store_category' );
$store_meta['terms'] = '';
if ( $terms ) {
if ( !is_wp_error( $terms ) ) {
if ( count( $terms ) > 1 ) {
$location_terms = array();
foreach ( $terms as $term ) {
$location_terms[] = $term->name;
}
$store_meta['terms'] = implode( ', ', $location_terms );
} else {
$store_meta['terms'] = $terms[0]->name;
}
}
}
return $store_meta;
}
// custom store meta
add_filter( 'wpsl_store_data', 'custom_result_sort' );
function custom_result_sort( $store_meta ) {
$custom_sort = array();
foreach ( $store_meta as $key => $row ) {
$custom_sort[$key] = $row['terms'];
}
array_multisort( $custom_sort, SORT_ASC, SORT_REGULAR, $store_meta );
return $store_meta;
}
Add class of term in listing:
<script id="wpsl-listing-template" type="text/template">
<?php
$listing_template = '<li class=" <%= terms %>" data-store-id="<%= id %>">' . "\r\n";
ajaxComplete function which adds line of title code before each group of term locations:
$( document ).ajaxComplete(function() {
$("#wpsl-stores ul li").each(function(){
var className = $(this).attr('class');
className = className.replace(/\s+/g, '');
$( "<div class='wpsl-stores-cityname "+ className +"'><p>" + className + "</p></div>" ).insertBefore( "#wpsl-stores ul li."+className + ":first" );
$("#wpsl-stores ul .wpsl-stores-cityname."+className+":first").addClass("firstofname");
$("#wpsl-stores ul .wpsl-stores-cityname:not(.firstofname)").remove();
});
});
It adds as many title lines as locations number in term so I’ve needed to add class to first one and remove those without – maybe it can be done in simpler way ??
Thanks again