Opened 10 months ago
Last modified 4 weeks ago
#62975 new defect (bug)
Twenty Twenty-Five: Exclude sticky posts when offset is used
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | 7.0 | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | Bundled Theme | Keywords: | has-patch needs-testing |
| Focuses: | Cc: |
Description (last modified by )
In Twenty Twenty-Five, there are several templates that use query loop blocks with offsets.
Sticky posts are not hidden by default when offset is used, which means that if a website has sticky posts, they show more than once when the templates are used.
The repeated content is not desired because it is not a good experience for visitors.
See this support request:
https://wordpress.org/support/topic/posts-loop-broken-when-complex-blog-template-used/
This can be solved by updating the query loops that have offsets to also ignore sticky posts.
The "ignore" option is planned to be added in WordPress 6.8. See https://core.trac.wordpress.org/ticket/62908
Another alternative would be to use "exclude" sticky posts, then the sticky would not be repeated, but it would not be shown at all.
Users can also remove the sticky status from their posts. But it is not so easy for users to discover that they can solve the problem that way.
Attachments (1)
Change History (15)
#3
@
10 months ago
Hi @poena, Thanks for bringing this to Trac!
I have been thinking about this and maybe we can completely remove sticky posts from offset queries, or add a custom filter to dynamically exclude sticky posts only when offset is used.
The former approach is simpler but more restrictive, while the latter offers more flexibility. What are your thoughts on this?
#4
follow-up:
↓ 5
@
10 months ago
Did you mean that the change should be made in the query loop block itself and not in the theme?
I think the expectation is that the behaviour of the query loop should match wp query, where the sticky posts are not removed by the offset.
#5
in reply to:
↑ 4
@
10 months ago
Replying to poena:
Did you mean that the change should be made in the query loop block itself and not in the theme?
Actually, that makes more sense. Perhaps we could restructure affected templates to either split the query (sticky posts + offset posts) or provide alternative templates without offsets?
#7
@
10 months ago
The testing instruction are:
Create a few sticky posts.
Go to Appearance > Editor > Templates
Open a template that uses query loops and has design alternatives.
Select a design that has multiple loops.
Save. View the template on the front of the site.
#8
@
10 months ago
Hello @poena Thanks for the quick repose. I can reproduce the issue. Also, I have tested it with various themes and learned that it's not an issue with the query loop block but with the theme template. Am I right? Please correct me if I am wrong
#9
@
8 months ago
- Milestone changed from Awaiting Review to 6.9
Yes the issue is in the theme templates / patterns. The designs with multiple query loop needs have sticky set to exclude.
#10
@
7 months ago
One alternative would be to apply a filter that only fires when the query loop block is used.
For that, you could leverage query_loop_block_query_vars (https://developer.wordpress.org/reference/hooks/query_loop_block_query_vars/), for example:
<?php /** * Don't prepend sticky posts if a Query Loop block uses an offset. */ add_filter( 'query_loop_block_query_vars', function ( $query_vars, $block ) { if ( ! empty( $query_vars['offset'] ) ) { $query_vars['ignore_sticky_posts'] = true; } return $query_vars; }, 10, 2 );
Obs: that would only apply when offset is > 0.
We would need to validate if that will conflict with your comment https://core.trac.wordpress.org/ticket/62975#comment:2.
Did https://github.com/WordPress/wordpress-develop/pull/8265/ fix this?
Then you can ignore this.
This ticket was mentioned in PR #9471 on WordPress/wordpress-develop by @akshat2802.
4 months ago
#11
- Keywords has-patch added
PR for : https://core.trac.wordpress.org/ticket/62975
#### Summary
This PR updates bundled theme templates (e.g., Twenty Twenty-Five, Twenty Twenty-Four) that use Query Loop blocks with an offset to set the default to ignore sticky posts.
#### Why
When a Query Loop with an offset does not ignore sticky posts, sticky posts can appear more than once in their designated sticky slot and again in the offset loop. This leads to duplicate content and a suboptimal reading experience.
#12
@
4 months ago
This is one possible approach to improving the experience in bundled theme templates (e.g., Twenty Twenty-Five), where Query Loop blocks with an offset may display sticky posts more than once.
When sticky posts are not ignored, they can appear both in their featured position and again later in the loop, which can feel repetitive for visitors.
This PR https://github.com/WordPress/wordpress-develop/pull/9471 updates affected templates to set "sticky": "ignore" by default when using offsets. If a site owner or administrator prefers a different behaviour, they can easily adjust the Query Loop settings in the Site Editor to enable sticky posts or select another option.
The change also aligns with the new ignore option introduced in WordPress 6.8
@
4 weeks ago
News blog with sidebar pattern in WordPress 6.7, with "sticky":"ignore" from the patch
#14
@
4 weeks ago
- Milestone changed from 6.9 to 7.0
The "sticky":"ignore" setting in the patch did not give me errors in WordPress 6.7.0, so that might be a viable option. The <select> dropdown shows "Include" there, but the sticky post (published after "4") is not included.
I'm moving this to 7.0 for more testing. If you think it is ready to commit within the next week, feel free to put it back to 6.9.
Update: Actually the
ignorecan't be used because it would cause a block validation error on versions below 6.8. Sigh.