Support

Account

Home Forums General Issues Users select a single category only

Solving

Users select a single category only

  • My aim is to have a setup so that users can select a single category only and for a set of specific custom fields to appear for that category (using the “field groups -> location types -> post category is equal to category name” function). Typically, WordPress has checkboxes for each category.

    categories

    My thinking is to do this via the “radio buttons for taxonomies” plugin, which changes the UI to a radio button, forcing a single selection:

    radio buttons

    Unfortunately, when clicking between these radio buttons, ACF doesn’t seem to trigger a change/load/refresh – it doesn’t detect that the category has been changed?

    Does anyone have any suggestions or perhaps another way of achieving the same thing?

  • You’ve probably figured this out. The cause of this is that the plugin you mention changes the name of the field from post_category[] to radio_tax_input[category][]. ACF is not detecting the category because it can’t find the category field. Using this plugin you will need to save the changes to the post for the correct field groups to appear.

    There may be a way to add to alter what ACF is submitting in the AJAX request in order to use the value set for this field. Unfortunately I’m not familiar enough with this to know if it can be done or not and it would probably take some extensive digging through the JS to figure it out.

    Alternately you might be able to use a single field group with a taxonomy field that only allows one selection and to use conditional logic for the remaining field in the group.

    Another possible solution is to not use the plugin your using and construct a custom callback for showing the category selection box that does not alter the name of the field used, unfortunately I’m not sure about this either. I would probably start by figuring out how the plugin that you’re using is defining the custom callback function and then use that in combination with my own meta box function that does not alter the field name. For a radio button you would just use post_category instead of post_category[]

  • Thanks John,

    Based on what you wrote, I thought I would see if there was any other plugin that didn’t change the name of the field.

    It turns out that a different plugin – “Adjust Admin Categories” – allows you to switch it to a radio button, and also seems to be compatible with ACF.

    Thanks

  • I did look for other plugins but did not find anything that was current. Glad you found a solution.

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

The topic ‘Users select a single category only’ is closed to new replies.