Support

Account

Home Forums Front-end Issues Unable add a new Taxonomy on the Front-end

Solving

Unable add a new Taxonomy on the Front-end

  • Hi all,

    I’m facing a small issue with my front-end form. The form publishes everything perfectly but I’m unable to add a new Taxonomy.

    So the functionality I’m trying to provide is a way for non-logged-in users to add a new Industry taxonomy from the front-end. This works perfectly in the backend. A + icon appears, click it, popup box appears, type the Industry name, click Add, done. Perfect. However, on the front-end the + icon appears (when logged in) but clicking it does not show the popup box.

    I don’t see any JS errors or anything that makes me think a script is not loaded. I’m just not sure what’s going on.

    The field I’m using is a Taxonomy field with the Create, Save and Load Terms checked. I’ve tried setting the field to be a Checkbox or Multi Select. The issue happens either way.

    So really I guess there are 2 issues:

    1. Any idea what I could be missing as to why the + icon does not open the popup on the front-end?
    2. How would allow non-logged-in users access to create terms?

    Any help or points in the right direction would be much appreciated.
    Thanks!

  • In order to add terms to a taxonomy a user must have the correct permissions to do so. In WP for categories this would be manage_categories. I doubt that there is any way to give this permission to non logged in users.

    What you would need to do is set up some other type of field, a text field for example where they can enter either one new term or possible a comma separated list, or maybe a repeater. Then use an acf/save_post filter to get the new terms to be added and use WP set post terms to update the post https://codex.wordpress.org/Function_Reference/wp_set_post_terms

  • Thanks John! I ended up just adding an “other” option which seemed to satisfy the client. Though I’m still going to try what you mentioned in case it comes up again in the future.

    I appreciate you taking the time to respond!

  • This is a related question (tell me if I rather should open a new issue instead):

    In order to add terms to a taxonomy a user must have the correct permissions to do so. In WP for categories this would be manage_categories.

    I have a logged in user with the manage_categories capability but I still do not see the ability to add new terms from the front-end. Is there any other capability that is needed as well?

  • I’m not really sure about all of the permissions needed, or even all the details to make it work. I’ve actually never used a taxonomy field on a front end form.

  • I discovered that by making the user a super admin (this is a multisite) the add term button appeared. Not even ordinary administrator worked.

  • Actually, by trial and error I nailed it down to a combination of edit_users and manage_network_users. If I add those two capabilities to a user that otherwise just have the read capability (like a subscriber) then the add term button appears and works.

  • That’s just weird, but I’d say that it is somehow tied to a WP permission issue.

    Does it make any difference based on the type of field you use, checkbox vs select for example?

  • Well, the weird part was caused by my code, it seems 🙂

    This is how it works: ACF is checking the manage_terms capability.

    At first I didn’t understand because manage_terms is not listed here:
    https://codex.wordpress.org/Roles_and_Capabilities

    It’s also not available in the User Role Editor plugin, which I was using to assign capabilities to roles.

    But manage_terms is a special capability that is created when you use register_taxonomy() to register a taxonomy:
    https://codex.wordpress.org/Function_Reference/register_taxonomy

    It is set up as a reference to another capability, in the example it is manage_categories. But in my case I had a custom taxonomy where the manage_terms was set to edit_users for some reason, and that explains it all!

Viewing 9 posts - 1 through 9 (of 9 total)

The topic ‘Unable add a new Taxonomy on the Front-end’ is closed to new replies.