Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@djrmom
Created November 20, 2018 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djrmom/ee8f97ce9d87d535ce560fcfee8de6c5 to your computer and use it in GitHub Desktop.
Save djrmom/ee8f97ce9d87d535ce560fcfee8de6c5 to your computer and use it in GitHub Desktop.
facetwp index attachments and add a media type data source
<?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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment