Home › Forums › Front-end Issues › Hardcode taxonomy values in frontend form › Reply To: Hardcode taxonomy values in frontend form
https://support.advancedcustomfields.com/forums/topic/default-value-for-the-taxonomy-field-type/, the second solution I gave works in the admin. You’ll need to play with this since it’s a front end form and depending on what type of field it is, for checkboxes and miulti select fields you want to return an array but for single select and radio you’ll want to return just a single term ID.
I’m guessing here about what the $post_id
value will be
add_filter('acf/load_value/name=taxonomy_field_name', 'default_term_for_taxonomy_field_name', 10, 3);
function default_term_for_taxonomy_field_name($value, $post_id, $field) {
if ($value === false && get_post_status($post_id) == 'new_post') {
$value = array(3);
}
return $value;
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.