facetwp custom sort facet

<?php
/**
 * custom sort order for a facet, this orders by facet_display_value but facet_value could also be used
 **/
add_filter( 'facetwp_facet_orderby', function( $orderby, $facet ) {
	if ( 'colors' == $facet['name'] ) { // change colors to the name of the facet
		$orderby = "FIELD(f.facet_display_value, 'Blue','Green','Red', 'Gray')";
	}
	return $orderby;
}, 10, 2 );