简体   繁体   中英

How to make the post scheduled, not pending - Gravity Forms

Okay, I have the code working wonderfully, but I still have to go in and change the post status from pending to published. Is there any way to make it scheduled? Here is the code:

add_filter('gform_field_value_rprs_day', 'populate_day');
add_filter('gform_field_value_rprs_time', 'populate_time');
/**
 * Automatically populate the current day and time on the submission page.
 *
 * @link http://www.gravityhelp.com/forums/topic/defaultdynamic-value-for-time
 * @link http://borishoekmeijer.nl/resolve-current-date-and-time-timezone-issue-in-wordpress/
 */
function populate_day($value) {
  return date( 'm/d/Y' );
}
function populate_time($value) {
  return date( 'g:i a', current_time( 'timestamp' ) );
}

add_filter("gform_post_data", "rns_set_press_release_date_and_time", 10, 3);      
/**
 * Set the date and time of a submitted Press Release.
 *
 * @link http://www.gravityhelp.com/documentation/page/Gform_post_data
 */
function rns_set_press_release_date_and_time($post_data, $form, $entry){
  //only do this when the form id is 1
  if($form["id"] != 1)
    return $post_data;

  //set post date to field on form if date provided; get from entry data
  //using a date field in mm/dd/yyyy format and a time field in 24 hour format
  $day = $entry["2"]; //pull the date value from the form data posted
  $time = $entry["11"]; //pull the time value from the form data posted, field 7 on my form

  // Set the day to what we put in the field
  $day_value = date( "Y-m-d", strtotime( $day ) );

  // Set the hours, minutes, and seconds to what we put in the field
  $time_hours = $time[1];
  // Search for "pm" in our time variable, and add 12 to the hours if we find it.
  if ( strpos( $time, "pm" ) ) { 
    $time_hours = $time_hours + 12;
  }
  $time_minutes = $time[3] . $time[4];
  $time_value = $time_hours . ":" . $time_minutes . ":00";

  // Set the post_date variable after we have our final date and time
  $post_date = $day_value . " " . $time_value;

  // $post_data["post_title"] = $time[0] . "1 is " . $time[1] . "2 is " . $time[2] . "3 is " . $time[3] . "4 is " . $time[4];
  $post_data["post_date"] = $post_date; // Change the post_date property to our post_date variable
  $post_data["post_date_gmt"] = get_gmt_from_date( $post_date ); //set the post_date_gmt

  return $post_data; //return the changed data to use when the post is created
}

Is there a line I can change/add to make it a scheduled post?

I've written an article with a working snippet here:

http://gravitywiz.com/schedule-post-date-field-gravity-forms/

If you'd prefer to use the snippet you're currently working with, I believe adding the following line (before the "return" statement) should make it work:

$post_data['edit_date'] = true;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM