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

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from

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.

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
Status: 🔎 Needs Review
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