I have two functions, createNewsletter()
and saveNewsletter($data)
. I get wrong post_status
value on wp_posts
table.
It seems to run adding wp_publish_post( $data->id );
after the wp_update_post
, but It's not clear to me why WP doesn't update the post_status
while "enforcing" it with wp_insert_post
or wp_update_post
WP functions.
I noticed it runs removing post_date
from the array definitions.
Here's my functions:
With the first one I put some data in an array in order to add it to db through a WP insert function:
$new_post = array(
'post_title' => 'Newsletter del '.$date,
'post_content' => "",
'post_status' => 'publish',
'post_date' => current_time('Y-m-d H:i:s'),
'post_author' => $loggedUser->ID,
'post_type' => 'newsletter',
'post_category' => array(0)
);
$post_ID = wp_insert_post($new_post);
With the second I want to save any modification to the newsletter and update the corrisponding fields:
$update_args = array(
'ID' => $data->id,
'post_title' => $data->properties->title,
'post_status' => 'publish',
'post_date' => date('Y-m-d H:i:s'),
'post_author' => $loggedUser->ID
);
$result = wp_update_post($update_args);
On both cases I'm expecting to get post_status
= publish
on the DB record, but I keep getting post_status
= future
after the execution of the first or the second function.
I noticed not passing post_date
can be the best option.
future
was being set because the timestamp when I use wp_insert_post($new_post);
uses current_time()
, that is a future time (+2 hours from now).
Another option still valid is wp_publish_post( $data->id );
that forces to set the publish
status.