Schedule a Post by Date Field with Gravity Forms

Schedule your Gravity Forms generated posts to be published at a future date. The scheduled date can be specified manually in the code or by the submitting user via Gravity Form Date and Time fields.

March 8th, 2016: Updated snippet to only set future publish date if date field has a value.

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.

Getting Started

  1. Check requirements

  2. Install the snippet

    • Copy and paste the entire snippet into your theme’s functions.php file.
  3. Configure the snippet

    • Change the form ID and the $date and $time variables to match your date and time field.

Configuration

Configuring the snippet requires you to set two parameters starting at line 20: Field ID and Date field ID.

// Change '123' to your form ID; change '7' to your Date field ID.
$config['123'] = array(
    'date' => 7,
);

With these two parameters set, the post will be scheduled at midnight on the date set in the Date field.

Setting the Post Time by Field Value

You can also specify a Time field in the snippet. Whatever time the user inserts into this field will be the time the post is scheduled for publishing.

// Change '123' to your form ID; change '7' to your Date field ID; change '8' to your Time field ID.
$config['123'] = array(
    'date' => 7,
    'time' => 8,
);

Bonus: Static Time, User-specified Date

It is also possible to allow the user to select the date the post should be published on but you (the admin) can set a static time for it to published. This is useful if you don’t want to overburden the user with options or if you like to publish on a consistent schedule.

To do this, use the same configuration above with two changes to your Time field:

  1. Set a default value with your desired publish time.
  2. Set the field’s visibility to “Hidden”. This will allow the default value to be submitted but the user won’t see the field on the front end.

If you have want to manually set the date and allow the user to select the time, just make those changes to your Date field instead!

FAQ

How do I apply this to multiple forms?

To apply this to multiple forms, add as many configurations as you’d like.

// You can add as many forms as you want...
$config['433'] = array(
    'date' => 7,
    'time' => 8
);

$config['532'] = array(
    'date' => 3,
    'time' => 4
);

Was this helpful?

If you’ve found this snippet helpful or have an idea to improve it, let us know in the comments!

Comments

    1. Brian Yerkes
      Brian Yerkes July 16, 2020 at 8:55 am

      With the date set in the past, it didn’t work for me. I presume it’s down to the fact that the relatively new “Advanced Post Creation” addon controls the post date of the submitted form. The settings allow for “entry date” or a “custom date & time” ; the latter allowing values like “Today” and “next week” apparently. I tried a merge tag from my date field as the value, but that didn’t work.

      Any ideas would be much appreciated, thanks!

    2. Ryan Donovan
      Ryan Donovan July 16, 2020 at 9:23 am

      Hello Brian, this is a strange interaction indeed. We would like to take a closer look into this for you. Could you please reach out to us via our support line found here with all the information you can regarding this issue as well as a form export and we would be more than happy to assist you.

    1. David Smith
      David Smith Staff January 24, 2018 at 11:23 am

      Hi Aldo, you’ll need something to expire the posts (like this plugin). Then you’ll need to find out where they’re storing the expiration date/time (probably in a custom field) and set that custom field on submission.

    2. KayBee
      KayBee August 22, 2018 at 1:29 pm

      A late reply, could help someone else… Yes, there is, and I am and not using the Post-Expirator plugin since it does not let you set the expiration time via custom/meta field by default. What I did was add a Start Time field (actually a Custom Field and selected Time as the type of input) in the form which saves to a custom/meta field, which is just simple text line with a time format to match your needs. Then I also added another time field this one to schedule/expire the post. Make sure to use 24 hour format for this, as I explained in an earlier comment.

    1. SUSANA
      SUSANA July 15, 2017 at 7:49 am

      DAVID, Many many thank!!

      One more thing, appears like this:

      {entry:date_created} / 2017-07-12 18:35:31

      Is it posible just with the day?, I mean without the time.

  1. Craig Tommola
    Craig Tommola August 3, 2016 at 2:47 pm

    For those afraid to let their users submit / create posts scheduled to publish at a certain date or time, whether they’ve been reviewed or not, change line 37 in the above sample: $post_data[‘post_status’] = ‘future’; changing future to draft makes the post stay as a draft, whether the date / time passes or not: $post_data[‘post_status’] = ‘draft’;

    That way you can still have an admin review the content and hit “schedule”.

    Reply
  2. alan egan
    alan egan June 1, 2016 at 8:17 am

    Hi David,

    Like Ricardo (above) I have a number of forms that I would like to schedule but the link to the pastie that you provided is empty. Can you let me have the snippet please.

    Many thanks, Alan

    Reply
  3. alan egan
    alan egan May 2, 2016 at 5:01 am

    Hi David,

    Thanks for your help, I have the wrong field ID’s inserted. All working perfectly now. I have lots of forms and am interested in but your pastie link for multiple forms (above) is empty. Could you repost that code please.

    Many thanks, Alan

    Reply
    1. David Smith
      David Smith Staff May 2, 2016 at 9:06 am

      Hm, not sure why that would happen. Unfortunately, it’s not something we can afford to dig into for our free resource. If you’d like to hire us for some one-off support, we’d be happy to help. Get in touch.

  4. alan egan
    alan egan April 27, 2016 at 5:42 am

    Hello David,

    Thanks for all your great work – Super helpful site.

    I have added the snippet and have the schedule calendar on the form but when I fill it in and post it gets published anyway.

    Am I missing something regarding the publish settings in the post title? I thought this snippet would override that.

    The site isn’t live but I could give you access

    Thanks in advance, Alan

    Reply
    1. David Smith
      David Smith Staff April 27, 2016 at 8:22 pm

      Hi Alan, if you’d like to include a pastie of your configuration of this snippet, I’ll be happy to take a look and make sure it’s setup correctly.

    2. David Smith
      David Smith Staff April 29, 2016 at 5:39 pm

      I don’t see anything out of sorts there. I just confirmed that this is working for me locally. Not sure what is happening on your end. If you’d like us to install this for you we do offer an installation service for $99. Get in touch if you’re interested,

  5. Riccardo
    Riccardo January 20, 2016 at 4:15 pm

    Hi David, I have a little problem with the code for two forms in the same page. When I schedule a post with image in next month the image not appear. Have you any idea? Thanks. Riccardo

    Reply
  6. Shana Festa
    Shana Festa September 8, 2015 at 5:16 pm

    This is exactly what I need, but it keeps throwing an error when I update my functions.php.

    This is what I am trying to add to the file:

    [code removed]

    Reply
    1. David Smith
      David Smith Staff September 19, 2015 at 7:34 pm

      Hi Shana, could you share a pastie with your functions.php code + the snippet? The code you shared here was mostly lost due to auto-formatting.

  7. Riccardo
    Riccardo September 24, 2014 at 3:57 pm

    Hi David, thanks for this code, work perfectly with only one form! I have two forms (with two ID). It’s possible to scheduling the posts created with two different forms with the same code?

    Thanks a lot Riccardo

    Reply
    1. David Smith
      David Smith Staff September 25, 2014 at 12:29 am

      Hi Riccardo, here is an example of setting this for multiple forms. You’ll want to remove the form ID from the filter name and then follow the template in that modified snippet to specify the correct fields for each form ID.

      Happy to answer any questions you have on this.

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.

Download Snippet

Schedule a Post by Date Field with Gravity Forms

This field is for validation purposes and should be left unchanged.