Last active
January 14, 2017 02:35
-
-
Save mgibbs189/4dd6865b7e2aab0c4c09ead022ac7d7f to your computer and use it in GitHub Desktop.
FacetWP - order facets by WooCommerce 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 | |
function fwp_term_orderby( $orderby, $facet ) { | |
if ( 'YOUR_FACET_NAME' == $facet['name'] ) { // Replace "YOUR_FACET_NAME" | |
$term_ids = get_terms( array( | |
'taxonomy' => str_replace( 'tax/', '', $facet['source'] ), | |
'fields' => 'ids', | |
) ); | |
if ( ! empty( $term_ids ) && ! is_wp_error( $term_ids ) ) { | |
$term_ids = implode( ',', $term_ids ); | |
$orderby = "FIELD(f.term_id, $term_ids)"; | |
} | |
} | |
return $orderby; | |
} | |
add_filter( 'facetwp_facet_orderby', 'fwp_term_orderby', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment