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!
Our guide looks into WordPress custom fields and how they stack up against the possibilities of ACF.
— Advanced Custom Fields (@wp_acf) July 18, 2022
https://t.co/hk3yibkHyk
© 2022 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.