Created
November 20, 2018 17:25
-
-
Save djrmom/ee8f97ce9d87d535ce560fcfee8de6c5 to your computer and use it in GitHub Desktop.
facetwp index attachments and add a media type data source
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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