function update_post_publish_time($entry_id, $form_id) {
if ($form_id == YOUR_FORM_ID_HERE) { // Replace YOUR_FORM_ID_HERE with the ID of your Formidable form
$publish_time = FrmProEntriesController::get_field_value_shortcode(array('field_id' => PUBLISH_TIME_FIELD_ID, 'entry' => $entry_id));
$post_id = FrmProEntriesController::get_post_id_by_key($entry_id);
$post = get_post($post_id);
if ($post) {
$post->post_date = $publish_time;
$post->post_date_gmt = get_gmt_from_date($publish_time);
wp_update_post($post);
}
}
}
add_action('frm_after_update_entry', 'update_post_publish_time', 10, 2);
Make sure you change the Form ID and Publish Time Field ID in the code above with your respective IDs. Hi Walter. Thank you for taking the time to review it and provide me with solutions. I'm getting an error on line 5 when running it.
Thanks.
Reinaldo
Error: Uncaught Error: Call to undefined method FrmProEntriesController::get_post_id_by_key()
Hi Phil, still working on it. I asked Formidable Forms twice already, and I got the "we'll evaluate if this is an option that would benefit a high number of users" answer every time.
Best,
Reinaldo
Thanks for the update. I don't think it's an option per se, it's a defect in the original solution. There is no point in future dating a post without setting the time - the whole point of future dating posts is to reach a particular audience at a specific date and time. FF need to finish what they started as this is a premium feature. 🙂
Hello, Here is the code I'm testing, and so far works with "Edit" and "Duplicate" Posts. It allows changing both the Date and Time of a post. The "date_field_id_1" is for the new date, "date_field_id_2" is for the new time. It comes from ChatGPT after many changes and adjustments. I hope it helps those in need.
add_action('frm_after_create_entry', 'change_post_time_from_date_fields', 30, 2);
add_action('frm_after_update_entry', 'change_post_time_from_date_fields', 30, 2);
function change_post_time_from_date_fields($entry_id, $form_id) {
// Get the post ID associated with the Formidable Forms entry
$entry = FrmEntry::getOne($entry_id);
$post_id = $entry->post_id;
// Get the value of the date fields that contain the new post date and time
$new_post_date = FrmProEntriesController::get_field_value_shortcode(array('field_id' => 'date_field_id_1', 'entry' => $entry_id)); $new_post_time = FrmProEntriesController::get_field_value_shortcode(array('field_id' => 'date_field_id_2', 'entry' => $entry_id));
// If the post ID and new date and time are set, update the post date and time
if ($post_id && $new_post_date && $new_post_time) {
$new_post_date_time = date('Y-m-d H:i:s', strtotime($new_post_date . ' ' . $new_post_time));
$new_post_date_time_gmt = get_gmt_from_date($new_post_date_time);
// Update the post date and time with the new date and time
$post_date = substr($new_post_date_time, 0, 19);
$post_date_gmt = substr($new_post_date_time_gmt, 0, 19);
$post = array(
'ID' => $post_id,
'post_date' => $post_date,
'post_date_gmt' => $post_date_gmt,
);
wp_update_post($post);
}
}
Note that in my case, my time field format is H:I, not H:I:s, as shown above. So check that your time field format matches the format above; otherwise, it does not work. Also, it requires a hidden field with [post_id] as the default value.
Thanks for the code, I will give it a try sometime. Perhaps we can send this to Formidable Forms so they can fix the defect in the solution. 🙂
Please login or Register to submit your answer