With Gravity Forms, allowing users to submit posts to your WordPress website couldn’t be easier. Currently, you can set the default status of the generated WordPress post as “Draft”, “Pending” or “Published”.
This snippet provides the ability to schedule the post to be published at a future date. It can be configured to publish on a user-defined date/time (via submitted form data), a static date/time, or a combination of the two.
View this code snippet on GitHub.Getting Started
Check requirements
- Make sure you have Gravity Forms installed and activated.
- Already have a license? Download Latest Gravity Forms
- Need a license? Buy Gravity Forms
- Make sure you have Gravity Forms installed and activated.
Install the snippet
- Copy and paste the entire snippet into your theme’s functions.php file.
Configure the snippet
- Change the form ID and the
$date
and$time
variables to match your date and time field.
- Change the form ID and the
Configuration Options
Not sure how to change the variables? Follow the step-by-step instructions below.
Setting the Form ID
View this code snippet on GitHub.Update 546
to the ID of your form. This will ensure that only the posts created by the form you specify are scheduled for the future.
Setting the Field IDs
View this code snippet on GitHub.Update the 7
on the first line to the ID of your Date field and the 8
on second line to your Time field. This is how the code knows which Date and Time field to use to set the scheduled publish date.
Bonus: Static Time, User-specified Date
View this code snippet on GitHub.With this option, the user selects which date the post should be published on; however, you (the admin) would set a static time for it to be published. This is useful when you don’t want to overburden the user with options.
Make sure to include a leading zero if you’re setting a single digit hour and a space between the numbers and the am/pm. The 24-hour time format is also supported.
Bad: | 2:30pm |
Good: | 02:30 pm |
Good: | 14:30 |
Was this helpful?
If you’ve found this snippet helpful or have an idea to improve it, let us know in the comments!