0

I need to exclude one post format from Wordpress search results.

Any suggestions on how to solve this issue?

2
  • 1
    Why would you want to have a content public but exclude it from internal search? Google will still index and display the post in its results Oct 5 '14 at 6:20
  • I have a specific WP theme.
    – Aineko
    Oct 6 '14 at 2:02
0

You could probably do it my modifying the loop through the pre_get_posts hook.

function wpse163459_search_exclude_post_format( $query ) {
    if( $query->is_main_query() && $query->is_search() ) {
        $tax_query = array( array(
            'taxonomy' => 'post_format',
            'field' => 'slug',
            'terms' => array( 'post-format-quote' ),
            'operator' => 'NOT IN',
         ) );
         $query->set( 'tax_query', $tax_query );
    }

}
add_action( 'pre_get_posts', 'wpse163459_search_exclude_post_format' );
1
  • It works! I got it. Thnx!
    – Aineko
    Oct 6 '14 at 2:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.