This answer for taxonomy terms order by “Category Order and Taxonomy Terms Order” plugin.
/**
* To add extra param for facet query
*/
add_filter('facetwp_query_args', function ($query_args, $class) {
if ($class->ajax_params['template'] == 'partner_posts') {
$tax_terms = get_terms(array(
'taxonomy' => 'your-taxonomy-name',
'fields' => 'ids',
'hide_empty' => true,
));
$query_args['tax_query'] = array(
array(
'taxonomy' => 'your-taxonomy-name',
'terms' => $tax_terms
)
);
$query_args['uid'] = 'your-uid'; //add uniqe uid to identify query seperatly
}
return $query_args;
}, 10, 2);
// add my filter to change the order by of the query done by WP_QUERY:
add_filter('posts_orderby', function ($order_by_statement, WP_Query $query) {
global $wpdb;
if (
!isset($query->query_vars['uid'])
|| (isset($query->query_vars['uid']) && $query->query_vars['uid'] !== 'your-uid')
) {
return $order_by_statement;
}
$table_prefix = $wpdb->prefix;
return " {$table_prefix}terms.term_order ASC"
. (!empty($order_by_statement) ? ',' : '')
. $order_by_statement; //keeps the current orderby, but also adds the term_order in front
}, 10, 2);
add_filter('posts_join', function ($join_statements, WP_Query $query) {
global $wpdb;
if (
!isset($query->query_vars['uid'])
|| (isset($query->query_vars['uid']) && $query->query_vars['uid'] !== 'your-uid')
) {
return $join_statements;
}
$table_prefix = $wpdb->prefix;
$join_statements .= ' ' . <<<QUERY
LEFT JOIN {$table_prefix}term_taxonomy
ON ({$table_prefix}term_taxonomy.term_taxonomy_id = {$table_prefix}term_relationships.term_taxonomy_id)
LEFT JOIN {$table_prefix}terms ON ({$table_prefix}terms.term_id = {$table_prefix}term_taxonomy.term_id)
QUERY;
return $join_statements;
}, 10, 2);