• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Filter Search results

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › Filter Search results

This topic is: resolved

Tagged: exclude, results, search, widget

  • This topic has 3 replies, 2 voices, and was last updated 9 years, 7 months ago by David Chu.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • November 6, 2013 at 12:52 pm #71294
    dvempy
    Member

    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
    November 6, 2013 at 3:40 pm #71316
    David Chu
    Participant

    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

    November 7, 2013 at 9:41 am #71485
    dvempy
    Member

    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');

    November 7, 2013 at 9:43 am #71487
    David Chu
    Participant

    Great!
    And now I want to know exactly what you're excluding. Just kidding! 😉
    Dave


    Dave Chu · Custom WordPress Developer – likes collaborating with Designers

  • Author
    Posts
Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Filter Search results’ is closed to new replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble