Skip to content

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

Merged
Mamaduka merged 3 commits intotrunkfrom
add/rest-posts-controller-sticky-support
Feb 4, 2025
Merged

REST API: Add support for the 'ignore_sticky_posts' argument#68970
Mamaduka merged 3 commits intotrunkfrom
add/rest-posts-controller-sticky-support

Conversation

@Mamaduka
Copy link
Copy Markdown
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
@github-actions
Copy link
Copy Markdown

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 <mamaduka@git.wordpress.org>
Co-authored-by: spacedmonkey <spacedmonkey@git.wordpress.org>
Co-authored-by: TimothyBJacobs <timothyblynjacobs@git.wordpress.org>
Co-authored-by: iamtakashi <iamtakashi@git.wordpress.org>

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

@TimothyBJacobs
Copy link
Copy Markdown
Member

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

@Mamaduka
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

@github-actions
Copy link
Copy Markdown

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
@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
@swissspidy
Copy link
Copy Markdown
Member

@Mamaduka PS there is a typo in the function name: gutenberg_modify_post_collection_paramt

last letter "t"

Kallyan01 pushed a commit to Kallyan01/gutenberg that referenced this pull request Feb 24, 2025
…ss#68970)


Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: spacedmonkey <spacedmonkey@git.wordpress.org>
Co-authored-by: TimothyBJacobs <timothyblynjacobs@git.wordpress.org>
Co-authored-by: iamtakashi <iamtakashi@git.wordpress.org>
lipemat added a commit to lipemat/types-js-boilerplate that referenced this pull request Mar 12, 2025
chriszarate pushed a commit to chriszarate/gutenberg that referenced this pull request Jul 1, 2025
…ss#68970)


Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: spacedmonkey <spacedmonkey@git.wordpress.org>
Co-authored-by: TimothyBJacobs <timothyblynjacobs@git.wordpress.org>
Co-authored-by: iamtakashi <iamtakashi@git.wordpress.org>
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

No open 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.

4 participants