Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude password protected posts from search #1789

Closed
wants to merge 1 commit into from

Conversation

cristianuibar
Copy link

Description of the Change

The problem we faced was the display of password-protected posts in the search results. Upon further investigation we were not able to hide password-protected posts via any existing hooks. Looking at past issues, we found this one: #1083 which had a PR: #1094 that was reverted at a later time. Upon testing the PR we managed to successfully hide posts from search results using it hence I am re-opening the PR with an additional hook to be able to show posts regardless of admin status if one might want that.

Alternate Designs

We attempted to hide password-protected posts from the search results (which is default WP behavior) via existing hooks with no success.

Benefits

Hide password-protected posts from search results. This behavior can be disabled via the included hook.

Possible Drawbacks

None of which I can tell so far.

Verification Process

Upon implementing this code on our test and production sites, we re-run the indexing process and then tested the default WP search results in the front-end of the site using different keywords that we knew previously returned password-protected posts.

Checklist:

  • I have read the CONTRIBUTING document.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests passed.

Applicable Issues

None so far.

Changelog Entry

Add support for hiding password-protected posts from search-results. Props @allan23 (#1094)
Add filter hook so you can still display password-protected posts from search-results. @cristianuibar

@tlovett1
Copy link
Member

tlovett1 commented Jun 2, 2020

Hmm, interesting.

Excluding password protected posts absolutely makes sense. I think there is a better way to do it than tricking the plugin into using meta.

I also wonder if ElasticPress should just not index password protected posts which people should not be using anyway.

@dinhtungdu
Copy link
Contributor

dinhtungdu commented Jun 5, 2020

WP_Query has an argument named has_password. IMO, we can add support for that arg to Post Indexable, then we can filter the search query to exclude password-protected posts.

@tlovett1
Copy link
Member

tlovett1 commented Oct 7, 2020

@dinhtungdu can you create a PR for that?

@sagarsdeshmukh
Copy link

Hi @tlovett1 , Are you planning to merge one PR from #1789 or #1913 which allow to skip password protected content from search?

@mckdemps
Copy link
Contributor

Being addressed through #1913

@mckdemps mckdemps closed this Feb 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants