I need to do this in my post in custom post type, I need when to day publish new post. After 1 year from today convert post status from publish to draft.
How can do that ?
I need to do this in my post in custom post type, I need when to day publish new post. After 1 year from today convert post status from publish to draft.
How can do that ?
Try this code (maybe working) , but i'am not sure cause not testing :
function amin_show_expire(){
global $wpdb;
$result = $wpdb->get_results("SELECT * FROM wp_posts WHERE post_type = 'CUSTOM' AND post_status = 'publish'");
if( !empty($result)) foreach ($result as $a){
$show_time = get_the_time("Y-m-d", $a->ID );
$show_time=date("Y-m-d", strtotime("+1 years", strtotime($show_time)));
if ( $show_time < date("Y-m-d")){//compare 1 year after post with current time
$my_post = array();
$my_post['ID'] = $a->ID;
$my_post['post_status'] = 'draft';
wp_update_post( $my_post );
}
} // end foreach
}
add_action( 'init', 'amin_show_expire' );
function.php
and show me this error WordPress database error: [Table 'cartan.wp_posts' doesn't exist] SELECT * FROM wp_posts WHERE post_type = 'serve' AND post_status = 'publish'
Commented
Aug 30, 2015 at 15:27