WordPress.org

Forums

Better Search
How to exclude results from search (7 posts)

  1. Jim Reekes
    Member
    Posted 1 year ago #

    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/

  2. Ajay
    Member
    Plugin Author

    Posted 1 year ago #

    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.

  3. pablooliva
    Member
    Posted 1 year ago #

    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.

  4. Ajay
    Member
    Plugin Author

    Posted 1 year ago #

    Thanks for the code pablooliva

  5. EzYRiDaH
    Member
    Posted 1 year ago #

    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

  6. Ajay
    Member
    Plugin Author

    Posted 1 year ago #

    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

  7. EzYRiDaH
    Member
    Posted 1 year ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Better Search
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.