Gists

1 month ago
<?php

add_filter( 'facetwp_facet_sources', function( $sources ) {
    foreach ( $sources['custom_fields']['choices'] as $key => $value ) {
        if ( 0 === strpos( $value, '_stcr' ) ) {
            unset( $sources['custom_fields']['choices'][ $key ] );
        }
    }
    return $sources;
});
3 years ago
<?php
/** inherit adds attachment indexing **/
add_filter( 'facetwp_indexer_query_args', function( $args ) {
    $args['post_status'] = array( 'publish', 'inherit' );
    return $args;
});

/** post_mime_type is the column in the posts table to add **/
add_filter( 'facetwp_facet_sources', function( $sources ) {
    $sources['posts']['choices']['post_mime_type'] = 'Media Type';
    return $sources;
});

/** modifies string for mine type
 ** example image/png becomes image
 **/
add_filter( 'facetwp_index_row', function( $params, $class ) {
    if ( 'post_mime_type' == $params['facet_source'] ) {
		  $value = $params['facet_display_value'];
		  $value = substr( $value, 0, strpos( $value, '/' ) );
		  $params['facet_value'] = $params['facet_display_value'] = $value;
    }
    return $params;
}, 10, 2 );