Title: Query Loop Block Variation not working
Last modified: October 4, 2023

---

# Query Loop Block Variation not working

 *  Resolved [nitrospectide](https://wordpress.org/support/users/nitrospectide/)
 * (@nitrospectide)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/query-loop-block-variation-not-working/)
 * I am trying to extend the Query Loop block with a custom query. I have created
   a variations.js file that is pulled in by my theme, and I did a simple test of
   extending a different kind of block from a different tutorial, and it all works
   fine – so I know this is part of the setup is in working order.
 * Now I am using code from developer.wordpress.org to create my query loop block
   variation, and it just doesn’t work for me. No new block shows up in my block
   inserter. Why?
 * I am using this chunk of definition code: [https://developer.wordpress.org/block-editor/how-to-guides/block-tutorial/extending-the-query-loop-block/#offer-sensible-defaults](https://developer.wordpress.org/block-editor/how-to-guides/block-tutorial/extending-the-query-loop-block/#offer-sensible-defaults)
 * Mine just changes the postType to ‘news’ since I do not have a ‘book’ CPT, but
   do have a news one.

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

 *  Thread Starter [nitrospectide](https://wordpress.org/support/users/nitrospectide/)
 * (@nitrospectide)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/query-loop-block-variation-not-working/#post-17130376)
 * Can anyone clarify what I might be getting wrong here?
 *  Moderator [threadi](https://wordpress.org/support/users/threadi/)
 * (@threadi)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/query-loop-block-variation-not-working/#post-17130853)
 * I think your complete code would be useful if one should be able to understand
   this. You can make it available, for example, at [https://gist.github.com](https://gist.github.com).
 *  Thread Starter [nitrospectide](https://wordpress.org/support/users/nitrospectide/)
 * (@nitrospectide)
 * [2 years, 7 months ago](https://wordpress.org/support/topic/query-loop-block-variation-not-working/#post-17138973)
 * [@threadi](https://wordpress.org/support/users/threadi/) Here are the contents
   for my variations.js file, which I pull in via enqueuing in functions.php:
 *     ```wp-block-code
       wp.domReady( function() {
   
           const MY_VARIATION_NAME = 'my-plugin/services-list';
   
           registerBlockVariation( 'core/query', {
               name: MY_VARIATION_NAME,
               title: 'Services List',
               description: 'Displays a list of Services',
               isActive: ( { namespace, query } ) => {
                   return (
                       namespace === MY_VARIATION_NAME
                       && query.postType === 'services'
                   );
               },
               icon: /** An SVG icon can go here*/,
               attributes: {
                   namespace: MY_VARIATION_NAME,
                   query: {
                       perPage: 6,
                       pages: 0,
                       offset: 0,
                       postType: 'services',
                       order: 'desc',
                       orderBy: 'date',
                       author: '',
                       search: '',
                       exclude: [],
                       sticky: '',
                       inherit: false,
                   },
               },
               scope: [ 'inserter' ],
               }
           );
   
   
       });
       ```
   
 * As mentioned in my original post, the enqueuing is working, and I can create 
   other block variations. But I will include my enqueuing code for completeness:
 *     ```wp-block-code
       function enqueue_block_variations() {
       	wp_enqueue_script( 
       		'my-block-variations', // handle for script once loaded
       		get_stylesheet_directory_uri() . '/js/variations.js', 
       		array( 'wp-blocks', 'wp-dom-ready', 'wp-edit-post' ) // loads dependencies
       	);
       }
       add_action( 'enqueue_block_editor_assets', 'enqueue_block_variations' );
       ```
   
 *  Thread Starter [nitrospectide](https://wordpress.org/support/users/nitrospectide/)
 * (@nitrospectide)
 * [2 years, 7 months ago](https://wordpress.org/support/topic/query-loop-block-variation-not-working/#post-17150903)
 * Is this functionality not yet in widespread use?
 *  Moderator [threadi](https://wordpress.org/support/users/threadi/)
 * (@threadi)
 * [2 years, 7 months ago](https://wordpress.org/support/topic/query-loop-block-variation-not-working/#post-17158853)
 * No, I think that’s been used rather little so far. Moreover, you have rather 
   few developers here in the forum who deal with it. I think you’d be better off
   with Stackoverflow or the Gutenberg team.
 * Looking at your request, I see 2 problems in your code:
 * a) The specification of the icon is incorrect. This leads to a JavaScript error.
   If you don’t have an icon, I think you can leave it out.
   b) In the JavaScript
   console, you should see that “registerBlockVariation” is not defined when loading
   the block editor. To complete this, add
 *     ```wp-block-code
       const { registerBlockVariation } = wp.blocks;
       ```
   
 * at the beginning of your variations.js file.
 * After that it should work. In my test, at least, it works.
 *  Thread Starter [nitrospectide](https://wordpress.org/support/users/nitrospectide/)
 * (@nitrospectide)
 * [2 years, 7 months ago](https://wordpress.org/support/topic/query-loop-block-variation-not-working/#post-17173176)
 * I somehow missed when your reply came in via email. Thank you! This fixes it.
   🙂
 *  Moderator [threadi](https://wordpress.org/support/users/threadi/)
 * (@threadi)
 * [2 years, 7 months ago](https://wordpress.org/support/topic/query-loop-block-variation-not-working/#post-17173296)
 * Nice if I could help. You are welcome to set the topic to solved.
 *  Thread Starter [nitrospectide](https://wordpress.org/support/users/nitrospectide/)
 * (@nitrospectide)
 * [2 years, 7 months ago](https://wordpress.org/support/topic/query-loop-block-variation-not-working/#post-17173305)
 * Done

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

The topic ‘Query Loop Block Variation not working’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 8 replies
 * 2 participants
 * Last reply from: [nitrospectide](https://wordpress.org/support/users/nitrospectide/)
 * Last activity: [2 years, 7 months ago](https://wordpress.org/support/topic/query-loop-block-variation-not-working/#post-17173305)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
