Skip to content

Instantly share code, notes, and snippets.

@djrmom
Last active April 25, 2018 18:25
Show Gist options
  • Select an option

  • Save djrmom/9b9d16c3f08cccd60d88045b7c6f866a to your computer and use it in GitHub Desktop.

Select an option

Save djrmom/9b9d16c3f08cccd60d88045b7c6f866a to your computer and use it in GitHub Desktop.
facetwp search attachments
<?php
/**
* make sure both publish and inherit (for attachments) are searched on the search page
* Relevanssi has an option to index attachments but the query facet detects does not include attachments
* because it does not include post_status inherit
*/
add_action( 'pre_get_posts', function( $query ) {
if ( $query->is_search() ) {
$statuses = $query->get( 'post_status' );
$query->set( 'post_status', array_merge( (array)$statuses, array( 'publish', 'inherit' ) ) );
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment