wordpressにて、投稿した記事を一定時間後に自動削除できるようにしたいと考えてます。
サイト等を参考にしてfunction phpに以下のように記述したのですが、うまくいきませんのでご助言等いただければ幸いです。
参考にしたサイトは以下のものです。
https://www.sofplant.com/blog/tech/schedule-to-draft-or-trash/
https://worklog.be/archives/2886
https://wporz.com/wp_cron_batch/#wp_schedule_single_event
left_secondはカスタムフィールドで変数として各記事に指定します。
function auto_delete_event() { if(!empty($post->left_second)){ wp_delete_post(get_the_ID()); } } add_action('auto_delete','auto_delete_event'); $delete_time = get_post_time('U', true) + get_post_meta(get_the_ID(), 'left_second', true); wp_schedule_single_event($delete_time, 'auto_delete', array());
回答1件
あなたの回答
tips
プレビュー