The “hide post/pages on searches” doesn’t work
-
Good morning,
I installed your plugin about a year ago to be able to hide some pages from WordPress search.
After the major update at the end of December 2024, where a special table was created to be able to store posts or pages to be excluded from search, the plugin doesn’t seem to work properly anymore (although I’m not 100% sure that the problem might have been this update): basically pages with the “Hide on search” check set are still displayed in search.
I have analyzed the plugin code and I think I have discovered the reason for this malfunction: when performing a WordPress search, the $query object is set by entering the ids of the posts/pages to be displayed in the condition called “post__in”. The plugin subsequently inserts the ids of the posts/pages to be excluded from the search in the condition called “post__not_in”.
The problem is that if a post/page id is present in both the “post__in” and “post__not_in” condition, WordPress gives precedence to the first condition, causing it to be displayed in the search results.
In my opinion, in order to exclude some posts/pages from the search, it is necessary to remove from the “post__in” condition the post/page ids present in the “post__not_in” condition, by means of, for example, PHP’s array_diff() function.
I tried modifying the plugin code on a test site and it seems to work. Can you run a check on what is being reported?
Sincerely.
The topic ‘The “hide post/pages on searches” doesn’t work’ is closed to new replies.