Skip to content

Instantly share code, notes, and snippets.

@mgibbs189
Last active January 14, 2017 02:35
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 mgibbs189/4dd6865b7e2aab0c4c09ead022ac7d7f to your computer and use it in GitHub Desktop.
Save mgibbs189/4dd6865b7e2aab0c4c09ead022ac7d7f to your computer and use it in GitHub Desktop.
FacetWP - order facets by WooCommerce term order
<?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