How to change status of post based on date

Labels

This Discussion is public

Notifications

Hello, I want to create posts using Forms i need help to set the status of the post based on Date Field. For example if user set the future date then set the status of post as scheduled.

Hi Muhammad,
This hook might be helpful - https://formidableforms.com/knowledgebase/frm_new_post/

having same issue... in the form for posting you can set a field for Post Date but it is not working for me

Hi Offerscode,
Thanks for pointing that out. I just tested it. It works for me. I have a date field in my Form. Then in the "Create post" action, I specified my date field as "Post Date" and set "Post Status" to "Automatically publish".

When I submit an entry with the current date, the post is published immediately. When I submit with a future date, the post is scheduled for the given date.

I think this is what Muhammad was asking.
Offerscode, which part is not working for you?

So I just did a test, and it is scheduled for tomorrow so that seems to be working thanks.

Glad that you made it work :)

So how do you create a scheduled date and time?

Looking at this. Does this seem right?

RE: https://formidableforms.com/knowledgebase/frm_new_post/#kb-examples

add_filter( 'frm_new_post', 'combine data and time into post_date', 10, 2 );
function change_my_post_date( $post, $args ) {
if ( $args['form']->id == 37 ) { //change 25 to the ID of your form
$datetime = $_POST['item_meta'][810] .' '. $_POST['item_meta']830];
//change each number (20, 21, 22, 23) to the ID of the field to insert
$post['post_date'] = $datetime;
}
return $post;
}

 

Also do I post this in the Snippet plugin or in the Customize HTML of the form? before /after?

Which code?

If it is PHP, you could add to functions.php or Code Snippet plugin (my preference).

If it Javascript, then it goes to Customize HTML --> After Fields

So how do you create a scheduled date and time?

Looking at this. Does this seem right?

RE: https://formidableforms.com/knowledgebase/frm_new_post/#kb-examples

this still doesn't work...where do I add it? Code Snippets?

add_filter( 'frm_new_post', 'combine data and time into post_date', 10, 2 );
function change_my_post_date( $post, $args ) {
if ( $args['form']->id == 37 ) { //change 25 to the ID of your form
$datetime = $_POST['item_meta'][810] .' '. $_POST['item_meta']830];
//change each number (20, 21, 22, 23) to the ID of the field to insert
$post['post_date'] = $datetime;
}
return $post;
}

Got it to work thanks

see other support ticket I created.

see
https://community.formidableforms.com/help-desk/schedule-post-date-and-time/

Reply to this Discussion