Hi there!
I have an acf_form()
that I’m using to create a custom post type from the front end. I want to set various meta_key
s and taxonomies by default. I’m still trying to wrap my head around acf/save_post
, so thanks in advance for any help and understanding.
What I was doing: using ACF fields that were hidden and readonly via jQuery with default values.
Why I don’t want to use this anymore: doesn’t seem very secure / seems hackable
What I would like to do:
Run wp_set_object_terms
AND wp_update_post
with acf/save_post
.
What I have so far, unsurprisingly, is not working…hopefully with this, though, someone will at least understand where I’m trying to go with this.
function my_default_fields($post_id) {
// Default Meta Key Array
$default_meta_values = array(
'_meta_val_1' => 'derp',
'_meta_val_2' => 'herp'
);
// Set Default Meta Keys Loop
foreach($default_meta_values as $meta_key=>$meta_value) {
update_post_meta($post_id, $meta_key, $meta_value);
}
wp_set_object_terms( $post_id, 'taxo_value', 'my_taxo' );
}
add_action('acf/save_post', 'my_default_fields', 20);
// Front-end Form
$options = array(
'post_id' => 'new_post',
'post_title' => true,
'new_post' => array(
'post_type' => 'my_custom_post_type',
'post_status' => 'publish',
),
'field_groups' => array(
1234
),
'return' => home_url('my-uri'),
'submit_value' => __("Create post", 'acf'),
'updated_message' => __("Post created", 'acf'),
'uploader' => 'wp'
);
acf_form($options);