add_filter( 'facetwp_facet_orderby', function( $orderby, $facet ) {
if ( 'my_color_facet_name' == $facet['name'] ) { // Change 'my_color_facet_name' to the name of your facet.
$term_ids = get_terms( [
'taxonomy' => 'pa_color', // Change 'pa_color' to the name of the attribute used in the Color facet's data source setting..
'term_order' => true,
'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;
}, 10, 2 );