WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.49k stars 4.19k forks source link

Query Loop: Sticky Post setting doesn't work in Categories #51936

Open PHuhn opened 1 year ago

PHuhn commented 1 year ago

Description

Setting sticky bit on posts with a category show the post as if sticky is not set, that is sorted on the defined Ordered By.

Step-by-step reproduction instructions

Current version: 6.2.2

I have 4 categories, each category has ONE post with the sticky set. I created 4 pages each with a Query Loop with the Inherit query from template turned off, thus setting STICKY POSTS option to Include and Taxonomy of of the appropriate -category-.

On each page I expected the sticky post as the first post, but the posts were sorted on the defined Ordered By, which is Newest to Oldest.

Screenshots, screen recording, code snippet

image

Environment info

No response

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

ndiego commented 1 year ago

Thank you for reporting @PHuhn. I have been able to confirm in the latest version of Gutenberg and WordPress 6.2.2.

PHuhn commented 1 year ago

In the years that I have worked with WordPress, I have never used Sticky Post.

It's sad that this is still a problem. I see that the problem has existed for over ten years on Stack Overflow. In this issue over a year ago: 38979, it seems to disappear into a group of loop issues/fixes.

liviopv commented 10 months ago

I ran into this recently and it is still reproducible on WordPress 6.4, Gutenberg 17.2+ and TT4.

ethanclevenger91 commented 5 months ago

Yeah, this actually seems to be "as intended", in a way. The WP_Query class will not load sticky posts if you're not is_home. That should be true in classic themes as well. The query loop block takes no action on the query if you leave the default sticky setting, and that's going to have to change.

I think the "Include" sticky setting needs an explicit value set (right now it's value is empty), and that needs to trigger using post__in in some block logic that currently lives in WordPress core.

ntsekouras commented 1 week ago

As @ethanclevenger91 mentions, this is problem in core. I think we should close this one and and track this there (search for existing trac ticket or create a new one).