Hello,
Thanks for the feeback! So there’s different points in your report:
- If you use the “Hide field” setting, the field won’t be displayed at all, which means it won’t be saved
- Yes, there are multiple ways to achieve what you want you want to do
- There is no such template tag as
{current:post:ID}
that can be used as default value for ACF fields in the ACF Extended: Forms UI
So it looks like you have a form that create a New Post. This form is displayed on the front-page. You probably want to set the “Relationship” value of the newly created post (and not the front-page ID), right?
The code you provided will work, but not as intended. This code will be executed in the front-end and the back-end, so be careful. The get_the_ID()
you’re using will retrieve the current post ID, when in the front-end, it will set the value as the front-page ID. Then in the back-end, it will be overwritten and set the value as the current back-end post.
This is weird behavior, and you should avoid it. Here is a way to achieve what you want to do:
You can keep you relationship field hidden in the front-end, using “Hide Field” setting. When your post is created, you can add a specific action that will be executed after the post creation and set the newly created post ID into your ACF field. Please see the “Advanced” tab of the “Post Action” for more code examples:
/*
* Do an action on post creation in the form named 'my-form'
* Please change the 'my-form' part of the hook name
*/
add_action('acfe/form/submit/post/form=my-form', 'my_form_post_save', 10, 5);
function my_form_post_save($post_id, $type, $args, $form, $action){
// Add the value of the newly created post in the 'my_relationship' field
update_field('my_relationship', $post_id, $post_id);
}
Hope it helps!
Regards.