jenny-r
12/10/2019 - 1:59 PM

facetwp order by facet_value

facetwp order by facet_value

<?php
/** order by facet value (value shown in url on selection) instead of display value (label) **/

add_filter( 'facetwp_facet_orderby', function( $orderby, $facet ) {
    if ( 'day_of_week' == $facet['name'] ) {
        $orderby = 'FIELD(f.facet_value, "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday")';
    }
    return $orderby;
}, 10, 2 );