<?php

/* Remove "INCH" from the raw value */
add_filter( 'facetwp_index_row', function( $params, $class ) {
    if ( 'barrel_length' == $params['facet_name'] ) {
    
        // format the value
        $params['facet_value'] = preg_replace("/[^0-9.]/", '', $params['facet_value']);
    }
    return $params;
}, 10, 2 );


/* Sort numerically */
add_filter( 'facetwp_facet_orderby', function( $orderby, $facet ) {
    if ( 'barrel_length' == $facet['name'] ) {
        $orderby = 'f.facet_value+0 ASC';
    }
    return $orderby;
}, 10, 2 );