How to add a query loop block variation to get a custom post type ordered according to numeric meta value

How to add a query loop block variation to get a custom post type ordered according to numeric meta value
I want to extend the core query block with a variation to get a custom post type provinces in ascending order of a numeric meta value 'population_size'. I have use just the php filter in the past to add a variation, but have found this not to be working, this was my initial approach: function register_query_loop_block_variation($variations, $block_type) { if ('core/query' !== $block_type->name) { return $variations; } $variations[] = array( 'name' => 'provinces', 'title' => __('Provinces', 'my-text-domain'), 'description' => __('Display provinces in ascending population size', 'my-text-domain'), 'scope' => array('inserter'), 'isDefault' => false, 'attributes' => array( 'query' => [ 'postType' => 'province', 'perPage' => -1, 'orderBy' => 'meta_value_num', 'order' => 'asc', 'metaKey' => 'population_size', ], ), ); return $variations; } add_filter('get_block_type_variations', 'register_query_loop_block_variation', 10, 2); What is the simplest way to do this?

Take Your Experience to the Next Level

New

Download our mobile app for a faster and better experience.

Comments

0
U

Join the discussion

Sign in to leave a comment

0:000:00