Skip to content

Instantly share code, notes, and snippets.

@elpuas
Created December 29, 2022 14:38
Show Gist options
  • Save elpuas/d06763f19916cbd67159571ffeb41b34 to your computer and use it in GitHub Desktop.
Save elpuas/d06763f19916cbd67159571ffeb41b34 to your computer and use it in GitHub Desktop.
Simple Query Variation
const SIMPLE_QUERY = 'loop-patterns/simple-query';
wp.domReady( function() {
wp.blocks.registerBlockVariation( 'core/query', {
name: SIMPLE_QUERY,
title: 'Simple Query',
description: 'Displays a Simple Query',
isActive: ( { namespace, query } ) => {
return (
namespace === SIMPLE_QUERY
&& query.postType === 'post'
);
},
icon: 'edit-large',
attributes: {
namespace: SIMPLE_QUERY,
query: {
perPage: 3,
pages: 0,
offset: 0,
postType: 'post',
order: 'desc',
orderBy: 'date',
author: '',
search: '',
exclude: [],
sticky: '',
inherit: false,
},
},
scope: [ 'inserter' ],
innerBlocks: [
[
'core/post-template',
{},
[ [ 'core/post-title' ], [ 'core/post-excerpt' ] ],
],
[ 'core/query-pagination' ],
[ 'core/query-no-results' ],
],
}
)
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment