0

I am trying to create a cron job to run on my server which deletes a custom post_type (post_type = event) from my databse based on a meta_key (st_date) and a meta_value (the date the event took place ie. 2013-04-30).

I want it to automatically delete any event that took place over 30 days ago from the current date. I have been unsuccessful so far, with trying to use the DATEDIFF() > 30 function. My issues so far have been with creating the mysql query to delete the events.

  DELETE FROM 'wp_posts', WHERE 'post_type' = 'event'
  INNER JOIN 'wp_postmeta' ON 'wp_post.post_id' = 'wp_postmeta.post_id'
  AND 'meta_key'='st_date' 
  AND 'meta_value'= '(DATEDIFF(NOW()) > 30)'

Any help would be appreciated.

  • 1
    Post your code please. Are you trying to create a real system cron job or a wp_cron job? – s_ha_dum Jun 5 '13 at 19:10
  • If that's your SQL, it's not working because there are no fields called meta_key and meta_value in wp_posts. – vancoder Jun 6 '13 at 0:51

Your Answer

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