Skip to content

Instantly share code, notes, and snippets.

@djrmom
Created February 22, 2018 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djrmom/a3ab6c8cbbad8418bbad44a8335ffc59 to your computer and use it in GitHub Desktop.
Save djrmom/a3ab6c8cbbad8418bbad44a8335ffc59 to your computer and use it in GitHub Desktop.
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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment