facetwp index file extension

djrmom

{{gist file=”custom-hooks.php” lang=”php”}}
<?php
/** index a url or file path value as the extension to create a file type facet
** facet datasource needs to be a value that contains a url or file path for the file that includes the file extension
**/

add_filter( ‘facetwp_index_row’, function( $params, $class ) {
if ( ‘my_facet_name’ == $params[‘facet_name’] ) {
$raw_value = $params[‘facet_value’];
$extension = end( explode ( ‘.’, $raw_value) );
if ( !$extension )
$params[‘facet_value’] = ”; // don’t index if this is empty
$params[‘facet_value’] = $extension;
$params[‘facet_display_value’] = $extension;
}
return $params;
}, 10, 2 );
{{/gist}}