WordPress.org

Support

Support » Plugins and Hacks » Better Search » How to exclude results from search

How to exclude results from search

  • Ajay,

    There’s a few pages I’d like to exclude from search results. I know there’s PHP code I can write for the normal WP search, but before I go down that route I’d like to hear your recommendation.

    I can classify what to exclude by the specific page, but I also have everything in a directory (set by the page’s parent). There’s also categories, or post types, etc.

    Before I started coding I found this plugin, Search Exclude.

    What I see, at least so far, is this isn’t excluding the page seen by the public on the web site. Actually, it’s filtering out those pages from the admin while searching for a page to edit in the WP editor. Exactly the opposite of what I was expecting.

    How do I exclude pages from Better Search results?

    https://wordpress.org/plugins/better-search/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Ajay

    @ajay

    There isn’t an easy way to exclude pages or posts from the search results in Better Search. It hasn’t been a requested feature yet, but I’ll put this on my list of things to add to the new update.

    If you’re comfortable with code, the main SELECT clause is around lines 303 where you could possibly pass a WHERE NOT IN ('IDS list') with the list of post or page IDs.

    I have this in my Contextual Related Posts and Top 10 plugins.

    Thanks Ajay for the response to Jim’s question. It helped me with a similar question.

    To expand on your answer and provide more direction for others, the SELECT clause is found in the following file wp-content/plugins/better-search/better-search.php, starting on line 605.

    I wanted to eliminate from the search results a particular post type as well as specific posts/pages. A sample of the code is available: http://pastebin.com/apPvG3Gg

    On line 11 of the sample the custom post type is eliminated and on line 33 specific post IDs are eliminated from the results.

    Plugin Author Ajay

    @ajay

    Thanks for the code pablooliva

    Hi Ajay,
    Really love your plugin, but would also really like a standard exclude option for pages 🙂
    Not really keen on hacking into code 🙁
    Any news on the update it is included in?
    Cheers

    Plugin Author Ajay

    @ajay

    EzYriDah, are you talking about excluding specific IDs or just all pages.

    The former option is what I am coding in. The latter option is already present. It’s under General Options

    Hi Ajay,
    Thanks for your fast reply. I’m looking for the option to filter out specific pages (in my case 1 page). Looking forward to the next update!
    Keep up the good work!
    Cheers

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to exclude results from search’ is closed to new replies.
Skip to toolbar