tomusborne / generateblocks

GenerateBlocks is a small collection of lightweight WordPress blocks that can accomplish nearly anything.
https://generateblocks.com
188 stars 18 forks source link

Bug: Query Loop shows posts in wrong order with "STICKY POSTS: Include" setting in block editor #1252

Open frzsombor opened 1 week ago

frzsombor commented 1 week ago

Description

If I add a Query Loop in a page and set "STICKY POSTS: Include", it shows the posts in the same order as the "STICKY POSTS: Ignore" setting, so basically it also ignores the posts' "sticky" status. The rendered page works correctly (with "Include", the sticky posts are on top, and below them are the non-sticky ones). This is caused by the fact that the WP REST API only has a simple sticky parameter that can be set true or false (for including or excluding sticky posts), but it always returns the posts in publish date order and ignores the posts' sticky attribute. I also found that a custom stickyPosts parameter is added by GB to the REST API request but it has no effect. I suggest that in this case, we should either order the posts correctly with React on the frontend, or extend WP rest api to respect the stickyPosts parameter and return the results accordingly.

Steps to reproduce

  1. Add 3 new posts in WP
  2. Set the second as "sticky"
  3. Create a new page, add a query loop
  4. Set "STICKY POSTS: Include" and then "STICKY POSTS: Ignore"
  5. Compare results

Expected behavior

When I set "STICKY POSTS: Include", sticky posts should be on top in the Query Loop.

Actual behavior

When I set "STICKY POSTS: Include", sticky posts are ignored and post are in the same order as with "STICKY POSTS: Ignore"

References:

https://developer.wordpress.org/rest-api/reference/posts/#arguments https://github.com/WP-API/WP-API/issues/2565 (old!)