WordPress / Learn

WordPress.org Learn - The canonical source for the code and content behind https://learn.WordPress.org
260 stars 89 forks source link

Hidden Lessons appear in search results #2735

Closed adamwoodnz closed 2 weeks ago

adamwoodnz commented 1 month ago

This production Lesson is set to be hidden:

Image

We added a new post meta _lesson_archive_excluded to the Lesson post type, to enable to hiding specific Lessons (eg. quizzes) from archive and search views.

This works in local development and for the lessons archive in production, but not with Jetpack search running in production. I have tested this on the staging site without Jetpack Search running and it works.

Steps to reproduce

  1. Log in to production
  2. Create a Lesson and privately publish it. This should mean admins can see it but not regular users. Use a name you can easily search for later.
  3. On the frontend navigate to the Lessons archive and locate your Lesson in the grid.
  4. In the admin check the post meta box in the sidebar for 'Hidden Lesson -> Exclude this lesson from the archive' Image
  5. Refresh the frontend archive and the Lesson should be hidden
  6. Search for your Lesson using the search box

Expected

The lesson remains hidden

Actual

The lesson is included in the search results

adamwoodnz commented 1 month ago

Related issue for filtering search results by Language: https://github.com/WordPress/Learn/issues/2577

adamwoodnz commented 1 month ago

The easiest way to solve this is likely using a taxonomy instead of post meta (see comments on https://github.com/WordPress/Learn/issues/2577). Given this only happens when searching specifically I think it can be addressed post launch.

adamwoodnz commented 1 month ago

Jetpack search indexing isn't picking up the new taxonomy, reopening while we investigate.

trakos commented 3 weeks ago

I've looked into it, and it appears that the indexing is picking up the new taxonomy correctly. It's only the search condition that isn't translated to ES. I've opened https://github.com/WordPress/Learn/pull/2843 as a potential fix - not sure if it that's the right approach, but it should at least showcase the problem.

adamwoodnz commented 2 weeks ago

@westnz @jonathanbossenger this taxonomy based filtering should be working now. https://learn.wordpress.org/?s=spam and https://learn.wordpress.org/?s=quiz&post_type=lesson both should be displaying content as expected.

I've migrated all the lessons that had the 'Hidden Lesson' post meta applied to the new Visibility taxonomy. From now on you can set this in the sidebar instead:

I'll be removing the old setting next.