jenny-r
2/22/2018 - 4:48 PM

facetwp sort by term_order

facetwp sort by term_order

<?php

add_filter( 'facetwp_facet_orderby', function( $orderby, $facet ) {
    if ( 'my_facet' == $facet['name'] ) { // change 'my_facet' to name of your facet
		
		/** get you terms in the term_order and make a list of them in the form:
		 ** $ordered_terms = '"term_slug_1", "term_slug_2", "term_slug_3"';
		 ** note that the double quotes need to be part of the variable itself
		 ** so that that it will output a string as shown in
		 ** https://facetwp.com/documentation/facetwp_facet_orderby/ "Sort by arbitrary values" **/
        
        $orderby = 'FIELD(f.facet_value, $ordered_terms)';
    }
    return $orderby;
}, 10, 2 );