Created
February 22, 2018 16:48
-
-
Save djrmom/a3ab6c8cbbad8418bbad44a8335ffc59 to your computer and use it in GitHub Desktop.
facetwp sort by term_order
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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