Skip to content
This repository has been archived by the owner on Nov 6, 2022. It is now read-only.

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

Open
kienstra opened this issue Sep 13, 2019 · 11 comments
Open

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

kienstra opened this issue Sep 13, 2019 · 11 comments

Comments

@kienstra
Copy link
Collaborator

kienstra commented Sep 13, 2019

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
Copy link
Member

lukecarbis commented Sep 13, 2019

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
Copy link
Collaborator Author

kienstra commented Sep 13, 2019

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
Copy link
Collaborator Author

kienstra commented Sep 13, 2019

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
Copy link
Collaborator Author

'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
Copy link
Member

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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

kienstra commented Oct 2, 2019

Another user reported this issue as well.

@lukecarbis
Copy link
Member

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
Copy link
Collaborator Author

kienstra commented Oct 2, 2019

Ah, interesting

@kienstra kienstra reopened this Oct 3, 2019
@martinbon
Copy link

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
Copy link
Collaborator Author

kienstra commented Oct 25, 2019

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants