Hello,
Thanks for the feedback!
The “Post Create” action will trigger 2 transition_post_status
:
new > draft
draft > publish
This is because the post needs to be created first in order to retrieve the “Generated ID”, so it can be used as “Post Title” in the Form UI. See screenshot.
Unfortunately, that logic can’t be bypassed, as it’s the only way to be 100% sure the new genereated post ID is correct.
Regarding the Post Schedule, note that you have to set a later post_date
during the post creation (or update), in order to correctly schedule it. Otherwise WordPress will simply create the post and immediately publish it because the date has passed.
In order to set a custom argument (such as post_date
) during the post creation, you’ll have to use the acfe/form/submit/post_args
hook (See documentation). This hook will let you customize the post arguments, just like when using the native wp_insert_post()
function (See documentation). I would recommend to check that function documentation, so you’ll get a good idea of all possible customization.
Regarding the post schedule on its own, here is a usage example that will schedule the post to +1day
after the form submission:
add_filter('acfe/form/submit/post_args/form=my-form', 'my_form_post_args', 10, 4);
function my_form_post_args($args, $type, $form, $action){
// schedule post
$args['post_date'] = date('Y-m-d H:i:s', strtotime('+1day', current_time('U')));
$args['edit_date'] = true;
// return
return $args;
}
You can check the strtotime()
PHP function documentation in order to understand how it works.
You’ll find some topics on Stackoverflow here and here about how the wp_insert_post()
works with scheduled dates.
Note that you don’t need to set the post_type
to future
in order to schedule a post. Even if it is set to publish
, WordPress will automatically schedule the post if it is set to a later date.
Regarding the Form UI settings allowing to set a future date, that setting is not available yet, because it has to be compatible with relative dates (+1day
) and absolute dates (Y-m-d H:i:s
), which makes it a bit more complex than other fields. It will come in a future update tho.
Hope it helps!
Have a nice day!
Regards.