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

REST API: Add support for the 'ignore_sticky_posts' argument #68970

Merged
merged 3 commits into from
Feb 4, 2025

Conversation

Mamaduka
Copy link
Member

What?

Closes #68570.
Alternative to #68595.

PR introduces a new ignore_sticky argument for the Posts collection endpoint, which maps to ignore_sticky_posts. This allows the Query Loop block display to be consistent between the editor and the front end.

Testing Instructions

  1. Have at least a sticky post on the blog
  2. Open the template using the editor's query loop block (index, archive, etc.).
  3. Notice the sticky post is at the top.
  4. Open the front of the site and see the sticky post at the top.

Testing Instructions for Keyboard

Same.

Screenshots or screencast

CleanShot 2025-01-30 at 20 25 47

@Mamaduka Mamaduka added [Type] Bug An existing feature does not function as intended REST API Interaction Related to REST API [Block] Query Loop Affects the Query Loop Block labels Jan 30, 2025
@Mamaduka Mamaduka self-assigned this Jan 30, 2025
Copy link

github-actions bot commented Jan 30, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: spacedmonkey <[email protected]>
Co-authored-by: TimothyBJacobs <[email protected]>
Co-authored-by: iamtakashi <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@TimothyBJacobs
Copy link
Member

What is different from this instead of including sticky=true?

@Mamaduka
Copy link
Member Author

The sticky=true only displays sticky posts, while false removes them entirely from Query. That argument doesn't mimic ignore_sticky_posts, it's just post__in/post__not_in for sticky posts.

See:https://github.com/WordPress/wordpress-develop/blob/trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php#L314-L336.

@Mamaduka
Copy link
Member Author

Track ticket for some additional context - https://core.trac.wordpress.org/ticket/35907.

Comment on lines +106 to +110
/*
* Honor the original REST API `post__in` behavior. Don't prepend sticky posts
* when `post__in` has been specified.
*/
if ( isset( $request['ignore_sticky'] ) && empty( $args['post__in'] ) ) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mamaduka Mamaduka force-pushed the add/rest-posts-controller-sticky-support branch from fec137f to 2660fef Compare February 4, 2025 09:52
@Mamaduka
Copy link
Member Author

Mamaduka commented Feb 4, 2025

I would like to merge this to unblock #66222. The discussion is still ongoing in core backport PR, and I can backport any proposed naming changes to the query argument.

Copy link

github-actions bot commented Feb 4, 2025

Flaky tests detected in 2660fef.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/13132749302
📝 Reported issues:

@Mamaduka Mamaduka merged commit 2670a56 into trunk Feb 4, 2025
64 checks passed
@Mamaduka Mamaduka deleted the add/rest-posts-controller-sticky-support branch February 4, 2025 10:41
@github-actions github-actions bot added this to the Gutenberg 20.3 milestone Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Query Loop Affects the Query Loop Block REST API Interaction Related to REST API [Type] Bug An existing feature does not function as intended
Projects
Development

Successfully merging this pull request may close these issues.

Query Loop: It doesn't show sticky posts at the top when the query type is the default in the editor.
3 participants