davidduckwitz
Forum Replies Created
Viewing 1 replies (of 1 total)
-
I’ve found Solution by myself.
Here’s what i’ve done, maybe it can help other Developers, too:1. Define you date when post should be expire (in my case now +28 days):
$date = new DateTime('now +28 days');
$expires = date_format($date, 'Y-m-d H:i:s');2. Create Post with wp_insert_post and get post ID
// Build Post Array $my_post = array( 'post_author' => wp_strip_all_tags($user_id), 'post_category' => array( $cat ), 'post_content' => $postContent, 'post_content_filtered' => '', 'post_title' => $value->name, 'post_excerpt' => '', 'post_status' => 'publish', 'post_type' => 'post' ); // Insert the post into the database and get ID $post_id = wp_insert_post( $my_post );3. Add Post Metas for eypiration (delete Posts if expired)
//create Post Meta (In this Case it's the expiration date for postexpire) $ts = get_gmt_from_date("$expires",'U'); update_post_meta($post_id, '_expiration-date', $ts); $opts['expireType'] = "delete"; $opts['id'] = $post_id; update_post_meta($post_id, '_expiration-date-options', $opts); update_post_meta($post_id, '_expiration-date-status','saved');Best Regards from Germany
Viewing 1 replies (of 1 total)