Support Forum
Support › MB Custom Post Type › Custom Taxonomy Block not respecting orderbyResolved
I have a custom taxonomy that is non-hierarchal (like tags) but I have sort=>true
.
I have also added php with a custom filter to get_terms_orderby
which sets $orderby = 'tr.term_order';
so that WordPress will remember my order. See here: https://cln.sh/L4N0ZGwV
This works correctly on the post edit screen, terms are displayed in the saved order (not alphabetically). See here: https://cln.sh/QKmgbmSg
However, in the Block Editor when I use the custom taxonomy block generated by MetaBox, the terms are sorted alphabetically. See here: https://cln.sh/0D4ScfCJ
How is the MB custom taxonomy Block in the Block Editor retrieving custom taxonomy terms?
I expected that my filter would affect the block. I have tried it at differing priorities by it doesn't seem to have an effect.
Thank you!
Hello Brandon,
The custom taxonomy block is not created by Meta Box, it is the standard feature of WordPress. You can register a custom taxonomy with coding and enable show_in_rest
to use the taxonomy block.
Is there any way using the MetaBox UI to pass args
when registering a custom taxonomy?
If I could add 'args' => array('orderby'=>'term_order')
to the $args
parameter when registering the custom taxonomy, I would not need additional filtering.
(Also, Thank you for explaining that WP creates the Block. For that, I submitted a ticket to Gutenberg: https://github.com/WordPress/gutenberg/issues/51240 )
Hello,
There isn't a way to pass the args manually when registering custom taxonomy with Meta Box UI. Also, I don't see the orderby
in the list of accepted args when registering the custom taxonomy with code, please check the documentation
https://developer.wordpress.org/reference/functions/register_taxonomy/
Hello. Yes, it can be confusing at first because args
is a sub-paramater of $args
in register_taxonomy()
register_taxonomy()
has an $args
parameter which also has an args
key (screenshot: https://cln.sh/f60ZffjL ) which accepts an Array of arguments to automatically use inside wp_get_object_terms()
for this taxonomy.
So wp_get_object_terms()
has an orderby
parameter which can be set to term_order
(screenshot: https://cln.sh/SY6PTrBS )
So outside of Meta Box when using register_taxonomy()
I can do soemthing like this:
register_taxonomy('breeds', 'post', array(
'hierarchical' => false,
'show_in_rest' => true,
'labels' => $labels,
'args' => array(
'orderby' => 'term_order'
)
));
Hello,
Meta Box UI does not support passing the custom args like that. Please use the code to register the custom taxonomy.