getblocklab / block-lab

A WordPress Admin interface and a simple templating system for building custom Gutenberg blocks.
https://getblocklab.com
GNU General Public License v2.0
415 stars 64 forks source link

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

Open kienstra opened 5 years ago

kienstra commented 5 years ago

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.

lukecarbis commented 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.

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

I think we can close this.

kienstra commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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

lukecarbis commented 5 years ago

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.

kienstra commented 5 years ago

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 commented 5 years ago

Another user reported this issue as well.

lukecarbis commented 5 years ago

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.

kienstra commented 5 years ago

Ah, interesting

martinbon commented 5 years ago

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.

kienstra commented 5 years ago

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