Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for taxonomies with mandatory selection #95

Open
greatislander opened this issue Dec 19, 2017 · 4 comments
Open

Support for taxonomies with mandatory selection #95

greatislander opened this issue Dec 19, 2017 · 4 comments

Comments

@greatislander
Copy link

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: default true, accepts bool
  • default_term: default null, accepts string (term name)

When allow_empty is set to false, the first term listed will be selected by default and the No <taxonomy name> option will be removed from radio / dropdown taxonomies. If default_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.)

@johnbillion
Copy link
Owner

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.

@nreynis
Copy link

nreynis commented Aug 2, 2019

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?

@tedw
Copy link

tedw commented May 16, 2022

@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!

@montchr
Copy link
Contributor

montchr commented Mar 3, 2023

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...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants