Home Forums General Issues Define a default taxonomy (radio button)


Define a default taxonomy (radio button)

  • I’m using the acf_form() function to allow certain users to submit data (new posts) to my website.

    I’m using the taxonomy field type in the radio button variant but I can’t figure out how to define a “default” case. It is possible when using the radio button field type but not when using the taxonomy field type.

    Any clue on how to do this?

  • You can try to add a filter that will select a default value if none is selected already. Perhaps something like this:

    add_filter('acf/load_value/name=your_taxonomy_field_name', 'set_default_taxonomy_selection', 10, 3);
    function set_default_taxonomy_selection($value, $post_id, $field) {
        // Check if the field has a value
        if (!$value && empty($_GET['post'])) {
            // Set the default term ID here
            $default_term_id = 7;
            $value = $default_term_id;
        return $value;
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.