Open ethanclevenger91 opened 1 year ago
Hey @ethanclevenger91! π
The reason I went heavy-handed with the wp_term_order_taxonomy_override_orderby_supported
filter, is because WordPress almost always explicitly passes name
as the orderby
.
(This is particularly problematic in the Terms Admin Screens where WordPress forces name
but we need to force our own custom one just to make the interface of the plugin function as intended in the first place.)
For example, if you search for wp_dropdown_categories()
usages in wp-admin
each of them has name
explicitly set as the orderby
, and there is no way to know if it is a default argument for the plugin to override or an override to the plugin back to name
again.
The best compromise I could muster is to have other filters in place (wp_term_order_taxonomy_supported
and wp_term_order_get_taxonomies
) to allow users some global interception point where other decisions could be made.
Lastly, this plugin was released before Term Meta as an API had been added into WordPress Core, which is partially why it doesn't use it by default β the other part is that I just think the extra database column is ultimately the most performant approach, even if it is somewhat invasive. π
It is plausible to refactor some of this plugin's code to drop support for the additional database column, only use meta, and use meta_value_num
as the orderby
instead, though I'm not 100% certain that approach will help you in your implementation, so I'm curious to hear more about that from you! π
I'm imagining a scenario where this plugin is installed and functional, but a developer may want opt-in behavior for the actual sorting of terms.
If the
wp_term_order_taxonomy_override_orderby_supported
filter is used to return false for a taxonomy, there is no way to get those terms in the ordered order. The following will not get short-circuited:If that filter is not utilized, and the default behavior is used, the following will sort by the custom order before sorting by name, rather than sort by just name:
The solution seems to by that you would either respect
name
when explicitly set as the desired order, or the filter above would have a conditional for whenorder
has been explicitly set as the desired order.My current workaround looks like this: