WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.34k stars 4.13k forks source link

Query Loop block: allow certain aspects of a query to be changed without losing permalink structure #63817

Open annezazu opened 1 month ago

annezazu commented 1 month ago

When using the Query Loop block, the permalink structure changes from something more recognizable and coherent (/page/2/) to something like this structure ?query-14-page=2 when you override certain simple settings to create a custom query. You can see an example of this here: https://block-museum.com/museum/ Here's a quick video:

https://github.com/user-attachments/assets/e092b424-1f42-4051-a6a3-075bc916b8ba

This is a pretty drastic change when you might just be trying to change the number of posts shown or which posts are queried. Opening this issue to understand what can be done technically to allow for potentially more changes to the query loop block without losing the relationship to the permalink structure.

amiii123malviya commented 1 month ago

Hello I would like to work on this issue ?

youknowriad commented 1 month ago

I'm not sure this is a real issue. The fact that each "local query" or "custom query" uses a separate argument in the url is intended because you can have multiple local queries in the same page and the pagination shouldn't impact all of them at the same time.

For queries that "inherit" global queries, it's easier to use the permalinks because there can be only one global query per page.

dhanson-wp commented 1 month ago

I ran into this issue, and this is what our developer discovered:

/page/X will show only when we activate the Inherit query from template option in the Query Loop block. It will render the pagination block using this condition. But when we do not use the inherit option, the pagination will use the format ?$page_key=%#% as coded in line 48 of that same file.

ntsekouras commented 2 weeks ago

I'd echo Riad above and I think we can close this one. I personally don't think there is a way to handle this differently..

mtias commented 2 weeks ago

I think we can make this look way better if we leverage the name attribute of a query block so it doesn't look like a random query id. For example, I name my query block "latest news" and I'd get to see ?latest-news-page=2.

ntsekouras commented 2 weeks ago

I think we can make this look way better if we leverage the name attribute of a query block so it doesn't look like a random query id. For example, I name my query block "latest news" and I'd get to see ?latest-news-page=2.

That's an interesting idea, but despite some technical concerns which we could explore later (like ensuring uniqueness of names across all post content) , my main concern is:

  1. A user names a Query Loop block in a published post
  2. Navigates to a different page of that block and that link with something like ?latest-news-page=2 is shared
  3. The user renames the Query Loop block
  4. The previously shared link doesn't work anymore.

I'd consider this a blocker, no? I'm not sure right now if we can work around it somehow..

mtias commented 1 week ago

Good point, but I don't think that's a blocker, sharing a paginated permalink like that and changing the query id would also "break". The worst outcome is also that the link won't paginate but the resource still loads.

ntsekouras commented 1 week ago

sharing a paginated permalink like that and changing the query id would also "break".

That's true, but changing the block's name is easy without indicating 'breakage' (of the paginated links shared before), while query id can only be edited through the code editor. If we're not considering this a blocker, I guess it's open for exploration to make this happen.