$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>theme development - Set Expiration Date of a Post from the Frontend with wp_insert_post|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

theme development - Set Expiration Date of a Post from the Frontend with wp_insert_post

matteradmin9PV0评论

i try to build a form that users posts from frontend, everything works fine but i need to know if it's possible, if i play with the 'post_date' => date('Y-m-d H:i:s')?

if i add a hidden field that generates the expiration day (+30 days from the post day) and then add it to the post with add_post_meta($post_id, 'expiration', $expDate, true);

anyone have any ideas how i can build something like this?

thanks a lot,
Philip

i try to build a form that users posts from frontend, everything works fine but i need to know if it's possible, if i play with the 'post_date' => date('Y-m-d H:i:s')?

if i add a hidden field that generates the expiration day (+30 days from the post day) and then add it to the post with add_post_meta($post_id, 'expiration', $expDate, true);

anyone have any ideas how i can build something like this?

thanks a lot,
Philip

Share Improve this question asked Jan 9, 2011 at 22:46 PhilipPhilip 2,0191 gold badge23 silver badges33 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 3

The post by itself is only data, it cannot perform such action as expiring itself. So you need some form of external control to act on it.

You can use WP Cron (see wp_schedule_event() and related) to run periodic task that will query for posts by your custom field and perform wanted action on them (trashing, cancelling published status, etc).

Some plugins handle this as well such as my Post Expiration Date, which does not require WP Cron. WP Cron is fine if you have it, but not everyone does and not all hosts support it.

Post a comment

comment list (0)

  1. No comments so far