Hello to all! Script add posts to wordpress'a database, in the field "post_status" I write the value "future", and in the field "post_date" and "post_date_gmt" - the date of publication. But when the publication date is reached, the status of the post does not change to "publish" and, accordingly, the post does not appear on the site :( Tell me how to be

post add code:

mysql_query ('INSERT INTO `wp_posts` (`post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`, `post_status`, `comment_status`, `ping_status`, `post_name`, `post_type`) values ("1", "' . date('Ymd H:i:s', time() + 60) . '", "' . date('Ymd H:i:s', time() + 60 - 3600*3) . '", "text post", "post title", "future", "1", "open", "post-title", "post");'); 
  • and if you add a deferred entry through the admin panel, it is published at the appointed time? - alenkins
  • I am responsible for the vehicle, because I am familiar with the situation. Yes. Moreover, if you run through already added posts and MANUALLY click on “update”, then all added entries will change their status depending on the time of publication: - those that are added with the last number will remain published - those that are added with the future number will become scheduled and will be published at the set time. - user216963
  • Yes, it works through admin panel - thetur
  • post a code snippet in question that adds deferred entries, we will understand - alenkins
  • Added a code snippet that adds a post with the date of publication a minute ahead - thetur

1 answer 1

When publishing a postponed post through the admin panel, WordPress not only places it in the database, but also runs the wp_cron task. Your code does not. Use to create a post WordPress features, such as wp_insert_post.