Filter Search results

Community Forums Forums General Discussion Filter Search results

This topic is: resolved

This topic contains 3 replies, has 2 voices, and was last updated by  David Chu 8 months, 3 weeks ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #71294

    dvempy
    Member
    Post count: 5

    I am trying to exclude certain post categories and pages from search results.

    I am using Eleven40 Pro.

    How can this be achieved?

    http://www.salmonds.co.uk
    #71316

    David Chu
    Participant
    Post count: 1318

    Hi,
    You can find the number of your category(s) and use this nice bit of code in your functions.php.

    http://www.jaredatchison.com/2011/10/20/exclude-categories-from-wordpress-search-results/

    That guy is a Genesis guy I think, but his solution would work with any WP theme.

    D


    Dave Chu · Custom WordPress Developer – likes collaborating with Designers

    #71485

    dvempy
    Member
    Post count: 5

    Hi David,

    Perfect! Thanks for your help, much appreciated.

    Filter by categories from search results

    add_filter( ‘pre_get_posts’, ‘ja_search_filter’ );

    function ja_search_filter( $query ) {

    if ( $query->is_search && !is_admin() )
    $query->set( ‘cat’,’-7′ );

    return $query;

    }

    Exclude all pages from search results

    function SearchFilter($query) {
    if ($query->is_search) {
    $query->set(‘post_type’, ‘post’);
    }
    return $query;
    }

    add_filter(‘pre_get_posts’,’SearchFilter’);

    #71487

    David Chu
    Participant
    Post count: 1318

    Great!
    And now I want to know exactly what you’re excluding. Just kidding! ;)
    Dave


    Dave Chu · Custom WordPress Developer – likes collaborating with Designers

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Filter Search results’ is closed to new replies.