Open kienstra opened 5 years ago
I think I know what causes this. It's come up before. The WordPress search function includes both the title and the post content when conducting a search. So in this example, any page which contains the text "Admissions" in the post content will show up too.
In terms of speed, here's a gif of how well it work for me running live. If the staging server this was running on is slow anyway, then the speed experienced in the screencast seems about right.
I think we can close this.
Hi @lukecarbis, Ah, great point. It's searching the content also.
Like you mentioned, searching for simply 'Admissions' might not return the right title, as 'Admissions' could be in the content of a lot of posts.
Though it should probably still return the correct page when typing the entire title, right?
The user reported that this issue exists even when typing the entire title.
Ah, maybe 'Admissions' was the page title.
In that case, with the current way WordPress search works, we wouldn't expect it to find that title if 'Admissions' is in the content of enough pages.
'Admissions' was the page title. So the search is currently behaving how we'd expect WordPress search to behave.
Still, maybe there's a way to limit the search to only page titles. May by passing an extra parameter to apiFetch, or filtering pre_get_posts
.
Some time searching didn't reveal any quick or easy way of doing this. There's no additional arguments we can send to the WP REST API endpoint to only search titles. We'd have to create a custom endpoint, and construct a custom database query.
I'd say that it's not worth including that extra code just to fix this one issue.
Yeah, this wouldn't be easy. Like you mentioned, it'd require some custom work with the REST API, probably with a custom SQL query.
Another user reported this issue as well.
Ah, interesting
I do believe I have the same/similar issue occuring.
It suggests posts nicely at first
But then when I type the suggested post type in there manually, it can't find it.
So it seems like it's totally ignoring the post title.
@martinbon, Thanks for bringing this up, and for your good screenshots. We've talked about prioritizing this.
You can check back here to see the status, a PR that fixes this will link to this issue.
Update: Please see this comment. This search is behaving how you'd expect WordPress search to, but it'd be best if this somehow only searched page titles, not also their content.
Here's a screencast of the issue the user provided. I cropped it to hide the URL, and added some text in it.
Steps To Reproduce (Though I couldn't reproduce this)
In the screencast, the requests for pages seem to take a long time.
Though in my local, the requests for pages complete quickly:
I'm not sure what could cause this, but I'll look at it.