Advertisement
chrishajer

Set future date on a pending post

Aug 20th, 2012
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.93 KB | None | 0 0
  1. <?php
  2. // http://www.gravityhelp.com/forums/topic/form-date-field-publish-date#post-71477
  3. // the 10 (priority), 2 (arguments) is documented here http://codex.wordpress.org/Function_Reference/add_filter
  4. // change the 64 here to your form ID
  5. add_action('gform_after_submission_64', 'set_schedule_date', 10, 2);
  6. function set_schedule_date($entry, $form){
  7.  
  8.         // get the post
  9.         $post = get_post($entry['post_id']);
  10.  
  11.         // see note here http://codex.wordpress.org/Function_Reference/wp_update_post#Scheduling_posts
  12.         $post->edit_date = true;
  13.  
  14.         // make sure it really is pending
  15.         $post->status = 'pending';
  16.  
  17.         // change post schedule date in format [Y-m-d H:i:s] based on input from the entry
  18.         // be sure to change the 18 here to your date input field
  19.         $post->post_date = date('Y-m-d H:i:s', strtotime($entry['18']));
  20.  
  21.         // update the post
  22.         wp_update_post($post);
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement