Query loop block variation with orderBy menu_order and CPT
-
Hello.
I’m trying to build a variation of the query block that displays items of a custom post type ordered by menu_order. I found this: https://www.ads-software.com/support/topic/query-loop-block-sort-by-menu_order/ and used the very helpful https://developer.www.ads-software.com/block-editor/how-to-guides/block-tutorial/extending-the-query-loop-block/ to create a Query block variation. On the front end it works fine.
However, in the block editor, it won’t display the posts. The block appears, but the loading icon isn’t replaced by the relevant CPT items.
Is this a bug? Am I doing something wrong? I’ve tried this on a bare WordPress install with the Twentytwentyfour theme and only a plugin to register the custom post type. Here’s my code:
import { registerBlockVariation } from '@wordpress/blocks';
const MY_VARIATION_NAME = 'myblockvariation/query/ordered-by-menu-order';
registerBlockVariation('core/query', {
name: MY_VARIATION_NAME,
title: 'Query ordered by menu_order',
description: 'Displays a list of posts ordered as you choose in the WordPress admin.',
isActive: ({ namespace, query }) => {
return (
namespace === MY_VARIATION_NAME
&& query.postType === 'person'
);
},
icon: 'book',
attributes: {
namespace: MY_VARIATION_NAME,
query: {
postType: 'person',
perPage: 3,
pages: 0,
offset: 0,
orderBy: 'menu_order',
order: 'asc',
author: '',
search: '',
exclude: [],
sticky: '',
inherit: false,
},
},
scope: ['inserter'],
innerBlocks: [
[
"core/group",
{
"align": "wide",
"layout": { "inherit": false }
},
[
[
"core/post-template",
{
"layout": {
"type": "grid",
"columnCount": 3
}
},
[
[
"core/group",
{
"style": {
"spacing": {
"padding": {
"top": "30px",
"right": "30px",
"bottom": "30px",
"left": "30px"
}
}
},
"layout": { "inherit": false }
},
[
["core/post-featured-image", { "isLink": true }],
["core/post-terms", { "term": "category", "separator": " | " }],
["core/spacer", { "height": "20px" }],
["core/post-title", { "level": 3, "isLink": true }],
["core/post-excerpt", {}],
["core/separator", { "className": "is-style-default" }]
]
]
]
]
]
],
['core/query-pagination'],
['core/query-no-results']
],
}
);Thanks in advance.
- You must be logged in to reply to this topic.