gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Change post terms variations priority

Open ltrihan opened this issue 2 years ago • 0 comments

What problem does this address?

I (and some other developers I know) spent hours trying to understand why the get_terms() function returned 'Invalid taxonomy' in an FSE pattern while the same code worked perfectly on a classic theme template.

All the details very well summarized below by @MarieComet (thanks again to you 🙏🏻 ) :

In FSE there is a Categories block which is used to list the categories of a post (it does a get_the_terms()). WordPress automatically creates variations of this block to list other public taxonomies. These variations are created on init, priority 10 by default. It is therefore important when you register_taxonomy() on init, to put yourself before (between 0 and 9), otherwise you will not have a Categories block variation for your custom taxonomies

The issue mentioned here is not just about not having a Categories block variation for our custom taxonomies If the priority is not specified on the register_taxonomy() function, the get_terms() function returns an error

What is your proposed solution?

To resolve my problem, after search few hours, I only had to add a priority under 10 to my register_taxonomy() function like this : add_action( 'init', 'ltrihan_register_creator_category', 9 );

Before to know it, I was using : add_action( 'init', 'ltrihan_register_creator_category');

And many (many) other people seem to declare their taxonomies without assigning a priority, and therefore use the default priority which is 10. 😬

The solution could be to change the default priority used by the core.

By the way, if it is possible, I really would like to be able to fix this "alone" with some help for my first contribution. I tried to do it so following these guidelines but I don't know how to test on my WordPress install if my fix is ok atfer change on gutenberg files. I am using Local By Flywheel.

Do I also need to create a ticket on https://core.trac.wordpress.org/ ?

Thanks a lot 🙏🏻

ltrihan avatar Mar 18 '24 21:03 ltrihan