block-lab icon indicating copy to clipboard operation
block-lab copied to clipboard

Entering title into Post field doesn't find the correct post

Open kienstra opened this issue 5 years ago • 11 comments

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)

  1. Create a Block Lab block with a Post field
  2. Set it to display pages (not posts)
  3. Create a new post, and add that block to it
  4. In the Post field, enter the name of a page
  5. Expected: the page appears
  6. Actual: the page didn't appear:
post-field

In the screencast, the requests for pages seem to take a long time.

Though in my local, the requests for pages complete quickly:

requests-pages

I'm not sure what could cause this, but I'll look at it.

kienstra avatar Sep 13 '19 04:09 kienstra

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.

2019-09-13 15-04-48 2019-09-13 15_05_55

I think we can close this.

lukecarbis avatar Sep 13 '19 05:09 lukecarbis

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.

kienstra avatar Sep 13 '19 05:09 kienstra

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.

kienstra avatar Sep 13 '19 17:09 kienstra

'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.

kienstra avatar Sep 13 '19 18:09 kienstra

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.

lukecarbis avatar Sep 15 '19 23:09 lukecarbis

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.

kienstra avatar Sep 15 '19 23:09 kienstra

Another user reported this issue as well.

kienstra avatar Oct 02 '19 16:10 kienstra

One option I just thought of – we could filter the query's "ORDERBY" parameter with the [posts_orderby](http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_orderby) filter, and do a MYSQL order by CASE or LOCATE.

Essentially combining this and this.

lukecarbis avatar Oct 02 '19 23:10 lukecarbis

Ah, interesting

kienstra avatar Oct 02 '19 23:10 kienstra

I do believe I have the same/similar issue occuring.

It suggests posts nicely at first blocklab-certificate-title

But then when I type the suggested post type in there manually, it can't find it. blocklab-certificate-title-invalid

So it seems like it's totally ignoring the post title.

martinbon avatar Oct 25 '19 11:10 martinbon

@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.

kienstra avatar Oct 25 '19 14:10 kienstra