-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Search Results template Query Loop Issues in 2024 #58949
Comments
Hi @rawdolphe - just thinking on this one a little further - my expectation is that the Query Loop in a search template will need to use the 'Inherit main query' option to actually show the search results. For any Query Loop block - selecting options manually will always set up a new query, rather than doing something like filtering the main query. |
Hi @jordesign, I am trying to make sense of this, but still can't work it out:
So far, all I can see is that the Search will only output everything; Posts AND Pages. Doesn't make sense. |
Can I close your other ticket? It is not beneficial to keep the discussion in two places. |
The Search block internally has a query as an attribute. You should be able to achieve this by defining registerBlockVariation( 'core/search', {
name: 'test/custom-search',
title: 'Test Search Block',
category: 'test',
attributes: {
query: {
post_type: 'page'
}
}
} ); See: #40585
These setting options appear when "Inherit query from template" is disabled. That is, it is used to |
Yes you can use the search block to pass different query parameters. In other words pass both the post type and the search term that the visitor enters into the field. This will only work when the search is initiated from that specific search block. These two search blocks will show different results:
The plugin probably uses a PHP filter, which would change the search site wide. |
Sure, I only posted here on your recommendation in my original post. Thank you. PS: I am not fully clued on on the terminology and/or the ins and outs of posting WordPress related issues. Sorry. For example, I am testing the Search Block (another 'search' related issue funny enough...) in the header and there are several bugs, where should I talk about it? can I explain it here as it's Search related or not? |
Thank you all for trying, I don't know what to do with it, sorry :) So I chose to pay a visit to my friend chatGPT and he offered the following code, I tested it and it's working now. My requirement is very simple in the Search 'behaviour'——Hopefully WordPress will update or fix (or improve...) the Search feature in the next update. For now, I am a happy camper. ——— Certainly! You can customize the search query in WordPress to only retrieve posts instead of both posts and pages. You can achieve this by adding a filter to modify the search query using the
This code hooks into the After adding this code snippet, your search results should only include posts, excluding pages. Make sure to test it to ensure it works as expected. I then asked: "Is there any potential issue with this code that I should be aware of?" to which he replied but will save the answer unless you are interested / curious... If you have a better option please let me know, I would be interested! |
I think it's best to report other issues as new issues.
That code should be fine. A similar code example is also introduced on the pre_get_posts hook. I think that the search result template and query loop block are currently working as per specifications, but is it safe to close this issue? |
Sure, please free to close it. Thank for the link, will have a look. Otherwise, where do I report the issues with the Search Block? |
@rawdolphe Thank you, I would like to close this issue.
Simply create a new issue. |
Description
The 'Search Results' template seems broken; when setting 'Query Loop' to Layout > Settings > POST TYPE > Post.
The search results pulls ALL posts / Always, regardless of the keyword used. Same when set to 'Page'.
Step-by-step reproduction instructions
Screenshots, screen recording, code snippet
No response
Environment info
WordPress 6.4.3 Default settings.
Problem with ALL browsers.
Problem with ALL OS.
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
The text was updated successfully, but these errors were encountered: