-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Add Ignore
option to sticky options for Query Loop block
#66222
Changes from 2 commits
7eaeb8c
03b5e04
1ce1e42
60cb502
2d9c182
ccc2ca9
a1a4394
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,3 +103,31 @@ | |
return $query; | ||
} | ||
add_filter( 'query_loop_block_query_vars', 'gutenberg_add_format_query_vars_to_query_loop_block', 10, 2 ); | ||
|
||
/** | ||
* Adds `ignore` option for sticky posts to the Query block. | ||
* | ||
* @see 'query_loop_block_query_vars' | ||
* | ||
* @param array $query The query vars. | ||
* @param WP_Block $block Block instance. | ||
* @return array The filtered query vars. | ||
*/ | ||
function gutenberg_add_ignore_sticky_posts_to_query_loop_block( $query, $block ) { | ||
ntsekouras marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if ( ! empty( $block->context['query']['sticky'] ) && 'ignore' === $block->context['query']['sticky'] ) { | ||
// Core function excludes all sticky posts if the `sticky` value is anything | ||
// other than `only`. We must reset that here, but it could potentially also | ||
// re-allow a sticky post that had been excluded in some other way. This | ||
// works okay for testing, but the real fix will need to be in the | ||
// core function. | ||
$sticky = get_option( 'sticky_posts' ); | ||
|
||
$query['post__not_in'] = array_diff( $query['post__not_in'], ! empty( $sticky ) ? $sticky : array() ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we exlude sticky posts? Ignore set below should include them and just list them in their natural order, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line 125 doesn't exclude them, it's actually re-including them after core already excluded them. That's what the comment above line 123 is about. |
||
|
||
// Ignore sticky posts. | ||
$query['ignore_sticky_posts'] = 1; | ||
} | ||
|
||
return $query; | ||
} | ||
add_filter( 'query_loop_block_query_vars', 'gutenberg_add_ignore_sticky_posts_to_query_loop_block', 10, 2 ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ const stickyOptions = [ | |
{ label: __( 'Include' ), value: '' }, | ||
{ label: __( 'Exclude' ), value: 'exclude' }, | ||
{ label: __( 'Only' ), value: 'only' }, | ||
{ label: __( 'Ignore' ), value: 'ignore' }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does this affect the editor? Shouldn't there be some change to the querying done clientside in the editor too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great question. In the editor, the sticky posts are already bugged on trunk. For example sticky posts do not show as the first posts when the "include" option is set, which is the default. The result in the editor and front already does not match. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should at least try to see if we can match the preview in editor. As @carolinan says it's already buggy and if I remember correctly is about what REST API supports how it maps with WP_Query. That's probably the reason (the mapping) for not having this as a separate option for sticky control. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Maybe a different control can be used with help texts? --cc @jameskoster There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps 'Ignore stickiness' is okay for now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ignore stickiness 😂 |
||
]; | ||
|
||
export default function StickyControl( { value, onChange } ) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The linting has to be addressed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed now