So I’m working on a front-end form and what I want to do is hardcode a taxonomy value in the following code:
<?php
acf_form(array(
'post_id' => 'new_post',
'post_title' => true,
'post_content' => false,
'return' => '%post_url%',
'new_post' => array(
'post_type' => 'spelmakers',
'post_status' => 'publish'
)
));
?>
Would something like this work?
'taxonomy' => 'function',
'taxonomy_term' => 'spelmaker'
If not, how should I do this? I’m able to add the taxonomy to the form and that works. But I would like to have it pre filled so users don’t have to click the taxonomy.
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;
}