0

My plugin is on two wordpress sites. The 'main' site sends a post to the child site. The child site receives the post via request to admin-post.php and inserts it as scheduled(future) to be published after some time with new title. Everytime the 'process' works, post is received and inserted, the title is changed BUT... not everytime the post is set as scheduled. Like 30-40% of the cases, the post just gets 'published'. It's weird and I don't know how to track this down and what causes it...?

Here's the sample code for receiving and inserting posts:

$post = array(
        'post_title' => $newTitle, 
        'post_date' => date('Y-m-d H:i:s', strtotime('+30 seconds'),
        'post_date_gmt' => gmdate('Y-m-d H:i:s', strtotime('+30 seconds'),
        'post_content' => $_POST['post_content'],
        'post_status => 'future'
        );
 wp_insert_post( $post )
3
  • There might be an issue with your wp-cron. I suggest you check the log in your cpanel/directAdmin. – Jack Johansson Jun 9 '17 at 13:06
  • There's a syntax error in your code, a missing closing single quote on both date lines. Have you considered using the REST API to create the post rather than a custom endpoint? – Tom J Nowell Jun 9 '17 at 13:08
  • There seem to be no errors in any logs - both wordpress sites or cpanel... Thanks for pointing the syntax errors Tom, I missed to quotes just in here, it's okay in the original code. I decided to do it with a custom endpoint, looked handier for my purposes. And it is... except for this issue which is very weird indeed. – user121456 Jun 9 '17 at 13:39
1

Why you want to set status as 'future' and publish is in next 30 seconds? I think that time is the issue. You can try some additional time like 5 minutes to publish post after insert, which may improve percentage of accuracy.

2
  • Well, I'm using 30 seconds for development purposes. In production it'll be like a few hours. The thing is that I don't want to rely on 'percentage of accuracy' so I'm wondering what is causing this and if I can fix it somehow to be sure that in production it'll be working 100% of the time? – user121456 Jun 9 '17 at 13:19
  • Well, apparently it works like a charm with additional time. Guess it's just the way it is – user121456 Jun 9 '17 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.