1

I am using wordpress as my cms..

i had need to schedule post programmatically every 60 seconds

This is the code i am using

 function techento_data_valid_schedule($data) {
  if ($data['post_type'] == 'post') {
    if ($data['post_status'] == 'publish') {
   // If post data is invalid then
   $time += 60;
   $data['post_status'] = 'future';
  $data['post_date'] = date('Y-m-d H:i:s', $time);
   $data->edit_date = true;

 }
 }
 return $data;
}

 add_filter( 'wp_insert_post_data', 'techento_data_valid_schedule', '99', 2 );

but when i publish the post... it sets the date to jan 1. 1970 ? Am unable to find the error in the codes ?

0

1 Answer 1

2

You're not setting your $time value anywhere, so when you get to the line $time += 60, you're getting $time = 0 + 60 which, in unixtime is Jan 1, 1970 at 00:01:00.

To correct this, you need to set your $time variable to whatever you need. If you want it to be the current time, try $time = time(); and then add 60 seconds.

Sign up to request clarification or add additional context in comments.

1 Comment

so what should i do to change it to 60 seconds?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.