-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Query block: Add a way to inherit the global $query
#25377
Comments
imo this should be the default, otherwise every blog post on WP performance and quicktips from 2022 onwards will start with making sure you change your query blocks to do this |
In FSE there definetely shouldn't be any possibilities for filtering. The offset and pagination settings could have their reason (e. g. making the first post bigger than the others etc.) but as you described above, After having read the Slack archive you linked and some thoughts I had yesterday, I see another big problem: As far as I understand (and as I described more detailed in #25607 (comment)) the Query Block uses the REST-Endpoint BUT: At the moment I can't see any chance that
Maybe I still have a fundamental misconception of the Query Block and please (!) correct me if I'm wrong. :) |
I agree with this assessment... The query block should have an option to just inherit everything from the main query. If that option is enabled (which should be the default as mentioned by @tomjn above), then most options should be hidden.
It's not that simple... Yes, the editor uses the REST API. But the frontend does not, it's a normal |
As a sidenote, I just tried something extremely simple just to test how well it works. gutenberg/packages/block-library/src/query-loop/index.php Lines 54 to 55 in 7a31f9c
I added this: global $wp_query;
if ( $wp_query && isset( $wp_query->query_vars ) && is_array( $wp_query->query_vars ) ) {
$query = $wp_query->query_vars;
} In my FSE theme I only have an The result is that the query block then behaves properly and it shows categories, search results, blog indexes etc for everything when browsing the site. Now, I'm not saying it will be as simple as pasting that code in the query block, it just goes to show that it is possible to inherit the global query without things falling apart. |
Hey all - Thank you for your explorations here! Much appreciated and needed for going forward. Also thank you @aristath for pinging (and you kind words) :). First of all the Query block will have to inherit the global
Both @mariohamann and @aristath remarks seem right and from some early explorations here are some thoughts (implementation doesn't exist yet).
Fist of all as mentioned above we should find a way to understand the context we are at (ex archive-posts) and enable/disable filters and/or set/unset values of the Query block. Something that occurred to me is that maybe during on creation of Query block (or some other place) we should allow the user to select whether to inherit the detected context or not. This should exist because we should not limit the user to have only on Query block. Simple use case would be to have a CPT archive page (like I think a big missing piece that I've started to explore is CPTs and Taxonomies. I know @mapk and @mariohamann work on this design wise as well.
Unfortunately for development speed's sake we need to enhance REST API even if it's not used on front-end. FSE has the goal to be as what you see is what you get, so I think we shouldn't build things out of that scope. |
Thank you again, @ntsekouras for your insights and explanations!
Just a quick thought:
Looking forward to coming explorations! 👍🏻 |
In my experimental theme I've been working on an alternative approach to @aristath's #25377 (comment). When I'm creating a template for category, tag, taxonomy, archive then I don't want to run the main query that has already been determined by WordPress. I just want to run the loop to render the inner blocks. eg. My
For more detail see bobbingwide/fizzie#11 |
I'm wondering if it was an intended behavior or some sort of unexpected use case caused by the fact the Query Loop block can exist without the Query block. I personally find it confusing that you have a choice to insert Query, Query Loop and Query Pagination blocks in any place. To give an example, it's unclear what would Query Pagination do on its own on the single post page. |
Intended or not, without the capability to extend the query loop block, I would not have continued experimenting with FSE. Both the query loop and pagination should work against the main query.
At present ( well, Gutenberg 9.3 ) the query pagination block does nothing on the front end and crashes in the editor. My investigation led me to wonder what happens if a post contains something like this:
or, how I'd intended to try it.
The answer, in my development environment with this logic implemented is:
This is what I would have expected. |
For context it was not allowed at first implementation: https://github.com/WordPress/gutenberg/pull/22199/files#diff-c1c5029a4cbcea0a6e41a1119a377d89f6ba86d683a9e654015a6b0f72103362R20. (I think this will be reverted and Pagination and Loop should only live under In some later PRs this changed in a first and not in depth attempt to support just that. To be able to use context, set in other ways (in IMO this is okay because it wasn't a complete solution and I think it's better to decouple the context detection in site editor. A promising approach of this is here: #27128 and design is being discussed to make this work well. |
Discussed briefly in a meeting on Slack so creating a ticket for it.
The query block should have an option to inherit its options from the global
$query
. This will allow us to avoid creating a separate template in FSE for each category/tag etc, and instead, have a single template for all categories.The blocks will still render the same way the user defines them, what changes is that if that query-block inherits the global query, it will get the posts from the context of the URL by inheriting the global
$query
.Settings for posts-per-page, offset etc can still work, but not the filtering aspect of the block's settings.
The text was updated successfully, but these errors were encountered: