Plugin Support
ying
(@yingscarlett)
Hi @jneug ,
GB’s query loop follows the same behaviour as the WP query loop.
So yes, it’s the intended behaviour.
However, if you want to change its behaviour when there’s no sticky posts found in the loop, try the steps below:
- Add an additional CSS class to the Grid block nested directly in the Query loop block, eg.
sticky-post-loop.
- Add this PHP code:
add_filter( 'render_block', function( $block_content, $block ) {
if ( ! empty( $block['attrs']['className'] ) && 'sticky-post-loop' === $block['attrs']['className'] ) {
$sticky_posts = get_option( 'sticky_posts' );
if ( empty( $sticky_posts ) ) {
$block_content = '';
}
return $block_content;
}
return $block_content;
}, 10, 2 );
-
This reply was modified 3 years, 2 months ago by
ying.
Thread Starter
jneug
(@jneug)
Thanks. I fixed it by modifying the query loop args like so:
add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
if ( isset($query_args['ignore_sticky_posts']) && $query_args['ignore_sticky_posts'] == 1 && count($query_args['post__in']) == 0 ) {
$query_args['post__in'] = array(0);
}
return $query_args;
}, 10, 2 );
Hi there! We haven’t heard back from you for a while now so we’re going to go ahead and set this topic as resolved. Feel free to reply if you need any more help.