Skip to content
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 loop not working with more than 3 results or changing results number in the block #1220

Closed
CarlosLongarela opened this issue Jan 22, 2024 · 10 comments
Labels
[Component] Themes & Customization Custom WC Themes, compatibility with core themes, and theme-adjacent customizations to sites [Type] Bug

Comments

@CarlosLongarela
Copy link

Query loop block it's not working if we change the number of results to show because saves as string and only works as string.

This happens in the WordCamp multisite. Checked in another multisite non-WordCamp and working fine.

To reproduce

Steps to reproduce the behaviour:

  1. Go to a WordCamp website.
  2. Create a new page.
  3. Insert a Query Loop Block.
  4. Change the number of Item Per Page to 4
  5. Results will say “No results found.”
  6. See error

We have the problem with our staging website https://wceutest24.wordcamp.org/2024/ and also live website https://europe.wordcamp.org/2024/

A recorded a video with several tests and the bug: https://video.tabernawp.com/conversations/fa2cdc82-7f9a-570d-9769-b2e351641649

@ryelle
Copy link
Contributor

ryelle commented Jan 22, 2024

How strange— it looks like changing the "items per page" value is also changing the offset — I tried this on a WC site and saw API requests like this:

  • /wp-json/wp/v2/posts?context=edit&offset=40&order=desc&orderby=date&per_page=4&sticky=false&_locale=user
  • /wp-json/wp/v2/posts?context=edit&offset=50&order=desc&orderby=date&per_page=5&sticky=false&_locale=user

Increasing the offset just added to it:

  • /wp-json/wp/v2/posts?context=edit&offset=51&order=desc&orderby=date&per_page=5&sticky=false&_locale=user

Off the top of my head, I don't know what could be interfering there.

@ryelle ryelle added [Component] Themes & Customization Custom WC Themes, compatibility with core themes, and theme-adjacent customizations to sites [Type] Bug labels Jan 22, 2024
@CarlosLongarela
Copy link
Author

Yes, it's very strange. I made a test in another multisite (that it isn't a WordCamp multisite) and the Query Loop works without any problem (and works with the number as integer and as string).

@pkevan
Copy link
Contributor

pkevan commented Jan 23, 2024

I'd imagine it's some filtering pre_get_posts for something else, since the offset always seems to be 40 plus the offset from the query loop block.

@ryelle
Copy link
Contributor

ryelle commented Jan 23, 2024

since the offset always seems to be 40 plus the offset from the query loop block.

In my testing, the offset was per_page * 10 + offset — when I set it to 2 per page, it's offset=20, 3 -> offset=30, and so on.

The strange part to me is that the API request is what's changed, so the API response is correct (to what it's asked for) but somewhere in the "fetch posts" logic it's changing the query.

@ryelle
Copy link
Contributor

ryelle commented Jan 23, 2024

Oh, it's not math but concatenation — perPage + offset. It looks like this was an issue in Gutenberg (WordPress/gutenberg#56439), and should have been fixed in 17.2, but WordCamp.org is still on 17.1.2. Updating GB should fix the issue.

@CarlosLongarela
Copy link
Author

Oh, fantastic news, but WordCamp.org could be updated to 17.2? or we have any solution to this to finish our team design and go live?

@pkevan
Copy link
Contributor

pkevan commented Jan 24, 2024

Gutenberg has been updated to 17.5.1, which resolves the issue.

@iandunn
Copy link
Member

iandunn commented Jan 24, 2024

It looks like that upgrade broke the query-filter block on events.w.org, see #1225 for details

@adamwoodnz
Copy link
Contributor

adamwoodnz commented Jan 26, 2024

Unfortunately we've had to temporarily roll back Gutenberg to 17.1.4 to fix the above issue with the Events homepage query filters, so this issue will be present again. We plan to ship another fix asap. Sorry for any inconvenience caused.

@adamwoodnz adamwoodnz reopened this Jan 26, 2024
@ryelle
Copy link
Contributor

ryelle commented Feb 1, 2024

The WordCamp network has been updated to Gutenberg 17.6, so this should be fixed again.

@ryelle ryelle closed this as completed Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Component] Themes & Customization Custom WC Themes, compatibility with core themes, and theme-adjacent customizations to sites [Type] Bug
Projects
None yet
Development

No branches or pull requests

5 participants