Title: Query Loop sticky only setting
Last modified: March 15, 2023

---

# Query Loop sticky only setting

 *  Resolved [jneug](https://wordpress.org/support/users/jneug/)
 * (@jneug)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/query-loop-sticky-only-setting/)
 * I want to use the Query Loop block to show sticky posts at the top of my start
   page. It works as long as there are some sticky posts, but otherwise it seems
   to show all posts. Is this the intended behavior? I expected it to be empty in
   that case.

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Support [ying](https://wordpress.org/support/users/yingscarlett/)
 * (@yingscarlett)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/query-loop-sticky-only-setting/#post-16563377)
 * Hi [@jneug](https://wordpress.org/support/users/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:
    1. Add an additional CSS class to the Grid block nested directly in the Query loop
       block, eg. `sticky-post-loop`.
    2. Add this PHP code:
 *     ```wp-block-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](https://wordpress.org/support/users/yingscarlett/).
 *  Thread Starter [jneug](https://wordpress.org/support/users/jneug/)
 * (@jneug)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/query-loop-sticky-only-setting/#post-16579032)
 * Thanks. I fixed it by modifying the query loop args like so:
 *     ```wp-block-code
       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 );
       ```
   
 *  Plugin Support [ying](https://wordpress.org/support/users/yingscarlett/)
 * (@yingscarlett)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/query-loop-sticky-only-setting/#post-16581374)
 * Great! 🙂
 *  [fernandoazarcon2](https://wordpress.org/support/users/fernandoazarcon2/)
 * (@fernandoazarcon2)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/query-loop-sticky-only-setting/#post-16651286)
 * 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.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Query Loop sticky only setting’ is closed to new replies.

 * ![](https://ps.w.org/generateblocks/assets/icon.svg?rev=3239461)
 * [GenerateBlocks](https://wordpress.org/plugins/generateblocks/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/generateblocks/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/generateblocks/)
 * [Active Topics](https://wordpress.org/support/plugin/generateblocks/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/generateblocks/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/generateblocks/reviews/)

 * 4 replies
 * 3 participants
 * Last reply from: [fernandoazarcon2](https://wordpress.org/support/users/fernandoazarcon2/)
 * Last activity: [3 years, 1 month ago](https://wordpress.org/support/topic/query-loop-sticky-only-setting/#post-16651286)
 * Status: resolved