Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a this code that delete some post meta at al 7:55 hour of the server:

if ( !wp_next_scheduled('borra_meta_datos') ) {
   wp_schedule_event( mktime(7, 55, 0, date('n'), date('j')), 'daily', 'borra_meta_datos' );
}

function borra_todos_los_meta_datos() {
   $args = array(
   'meta_key' => 'destacados',
   'post_status' => 'publish',
   'numberposts' => -1,
   'category' => -14
);
$allposts = get_posts($args);

foreach( $allposts as $postinfo) {
   delete_post_meta($postinfo->ID, 'destacados');
}

$args = array(
   'meta_key' => 'portada',
   'post_status' => 'publish',
   'numberposts' => -1
);
$allposts = get_posts($args);

foreach( $allposts as $postinfo) {
   delete_post_meta($postinfo->ID, 'portada');
}

$args = array(
    'meta_key' => 'slider',
    'post_status' => 'publish',
    'numberposts' => -1
);
$allposts = get_posts($args);

foreach( $allposts as $postinfo) {
   delete_post_meta($postinfo->ID, 'slider');
}
}
add_action('borra_meta_datos', 'borra_todos_los_meta_datos');

All the week the code works fine, but today the code executed early that the hour, i dont know if i am doing something wrong. Additionally i have another code that program all the post of specific user at 3 am of the local hour but today all the posts appear like lost schedule.

function programa_post($data, $postarr){
    $hora_de_publicacion = 3;
    if( $data['post_type'] == 'page' ){
        return $data;
    }
    global $current_user;
    get_currentuserinfo();
    if($current_user->user_login == 'luis' or $current_user->user_login == 'jorge'){
        $hora_actual = date('H', current_time('timestamp', 0));
        //Forget this if :S
        if($hora_actual >= 3 && $hora_actual <= 23){
            $time_3am = mktime($hora_de_publicacion, 0, 0, date('n'), date('j'));
            $data['post_date'] = date('Y-m-d H:i:s', $time_3am);
            $data['post_date_gmt'] = date('Y-m-d H:i:s', $time_3am - ( get_option( 'gmt_offset' ) * 3600 ));
        }elseif($hora_actual >= 0 && $hora_actual < 3){
            $time_3am = mktime($hora_de_publicacion, 0, 0, date('n'), date('j'));
            $data['post_date'] = date('Y-m-d H:i:s', $time_3am);
            $data['post_date_gmt'] = date('Y-m-d H:i:s', $time_3am  - ( get_option( 'gmt_offset' ) * 3600));
        }
    }

    if(trim($data['post_excerpt']) == ""){
        $data['post_excerpt'] = ' ';
        return $data;
    }else{
        return $data;
    }

    return $data;
}
add_filter('wp_insert_post_data', 'programa_post');

i dont know if is problem of code or error of cron, i am lost :(

share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.