Advertisement
Abubakar1309

Wp_update post

Jun 27th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. if ( $post_date < strtotime( "tomorrow" ) ) {
  2. $status = 'publish';
  3. $newpostdata['post_status'] = $status;
  4. $newpostdata['post_date'] = date( 'Y-m-d H:i:s', $post_date );
  5.  
  6. // Also pass 'post_date_gmt' so that WP plays nice with dates
  7. $newpostdata['post_date_gmt'] = gmdate( 'Y-m-d H:i:s', $post_date );
  8.  
  9. } elseif ( $post_date > strtotime( 'today' ) ) {
  10. $status = 'future';
  11. $newpostdata['post_status'] = $status;
  12. $newpostdata['post_date'] = date( 'Y-m-d H:i:s', $post_date );
  13.  
  14. // Also pass 'post_date_gmt' so that WP plays nice with dates
  15. $newpostdata['post_date_gmt'] = gmdate( 'Y-m-d H:i:s', $post_date );
  16. }
  17.  
  18. if ('insert' == $operation) {
  19. $err = wp_insert_post($newpostdata, true);
  20. } elseif ('edit' == $operation) {
  21. $newpostdata['ID'] = $post_id;
  22. $err = wp_update_post($newpostdata);
  23. }
  24.  
  25.  
  26.  
  27. foreach ( $my_posts as $post ) {
  28. update_post_meta( $post->ID, 'related_posts', array( 12, 23, 42 ) );
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement