Custom Taxonomy Block not respecting orderby
Support › MB Custom Post Type › Custom Taxonomy Block not respecting orderbyResolved
- This topic has 5 replies, 2 voices, and was last updated 1 year, 11 months ago by
Peter.
-
AuthorPosts
-
June 5, 2023 at 6:45 AM #42041
brandonjp
ParticipantI 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/L4N0ZGwVThis 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!
June 5, 2023 at 7:49 PM #42071Peter
ModeratorHello 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.June 5, 2023 at 11:38 PM #42078brandonjp
ParticipantIs 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 )
June 6, 2023 at 8:48 PM #42087Peter
ModeratorHello,
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/June 6, 2023 at 9:50 PM #42090brandonjp
ParticipantHello. Yes, it can be confusing at first because
args
is a sub-paramater of$args
inregister_taxonomy()
register_taxonomy()
has an$args
parameter which also has anargs
key (screenshot: https://cln.sh/f60ZffjL ) which accepts an Array of arguments to automatically use insidewp_get_object_terms()
for this taxonomy.So
wp_get_object_terms()
has anorderby
parameter which can be set toterm_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' ) ));
June 7, 2023 at 9:17 PM #42105Peter
ModeratorHello,
Meta Box UI does not support passing the custom args like that. Please use the code to register the custom taxonomy.
-
AuthorPosts
- You must be logged in to reply to this topic.