Open greatislander opened 6 years ago
Yeah I'd definitely be happy to take a look at a PR for that.
There's some semi-related code in place already which allows for a fallback default term from a stored option if you use a taxonomy term in the permalink structure.
See also #71.
By reading the documentation I was under the assumption that required
option was doing just that.
But it seems it is just adding a required attribute (and only in the dropdown widget) that has no effect at all (at least in Gutemberg) because the taxonomy still accepts the empty value. Shouldn't that be the role of the required option?
@nreynis I was also surprised to find this out about required
. Do you have a preferred solution? I’m considering this plugin https://wordpress.org/plugins/required-taxonomies/ Thanks!
I've been hoping for this feature as well, so I investigated the Required Taxonomies plugin mentioned in the previous comment. Unfortunately the author of that plugin has decided to make custom post type support a premium feature... (but it's licensed GPLv2 and the code itself looks pretty minimal aside from the embedded promotional stuff, so it's prob not too hard to adapt...)
I'm wondering if you'd be interested in a PR which adds support for registering a custom taxonomy where a term must always be selected (same behaviour as the
category
taxonomy). I can think of a few approaches to this but my preference would be to add two parameters to the registration function:allow_empty
: defaulttrue
, acceptsbool
default_term
: defaultnull
, acceptsstring (term name)
When
allow_empty
is set tofalse
, the first term listed will be selected by default and theNo <taxonomy name>
option will be removed from radio / dropdown taxonomies. Ifdefault_term
is set to a string, a matching term will created and selected by default (or selected if it exists). Thoughts?(Note: the
default_term
could be used for taxonomies which allow no selection as well, so maybe this could be two PRs.)