wp query - cron job for custom post type not working since Wordpress 5

Since Wordpress 5.1 (or 5 in general) I have a problem with a cron job.This cron top is filtering expired custom posts (

Since Wordpress 5.1 (or 5 in general) I have a problem with a cron job.

This cron top is filtering expired custom posts (coupon) and will mark it "not reliable" however its not working anymore. Unable to find the problem and need some help.

This the code:

 function clpr_coupon_prune() {
    global $clpr_options;

    $message = '';
    $links_list = '';
    $subject = __( 'Clipper Coupons Expired', APP_TD );

    if ( ! $clpr_options->prune_coupons ) {
        return;
    }

    // Get all coupons with an expired date that have expired
    $args = array(
        'post_type' => APP_POST_TYPE,
        'expired_coupons' => true,
        'posts_per_page' => -1,
        'fields' => 'ids',
        'no_found_rows' => true,
        'meta_query' => array(
            array(
                'key' => 'clpr_expire_date',
                'value' => '',
                'compare' => '!=',
            )
        )
    );
    $expired = new WP_Query( $args );

    if ( isset( $expired->posts ) && is_array( $expired->posts ) ) {
        foreach ( $expired->posts as $post_id ) {
            wp_update_post( array( 'ID' => $post_id, 'post_status' => 'draft' ) );
            $links_list .= html( 'li', get_permalink( $post_id ) ) . PHP_EOL;
        }
    }

    $message .= html( 'p', __( 'Your cron job has run successfully. ', APP_TD ) ) . PHP_EOL;
    if ( empty( $links_list ) ) {
        $message .= html( 'p', __( 'No expired coupons were found.', APP_TD ) ) . PHP_EOL;
    } else {
        $message .= html( 'p', __( 'The following coupons expired and have been taken down from your website: ', APP_TD ) ) . PHP_EOL;
        $message .= html( 'ul', $links_list ) . PHP_EOL;
    }

    $message .= html( 'p', __( 'Regards,', APP_TD ) . '<br />' . __( 'Clipper', APP_TD ) ) . PHP_EOL;

    if ( $clpr_options->prune_coupons_email ) {
        $email = array( 'to' => get_option( 'admin_email' ), 'subject' => $subject, 'message' => $message );
        $email = apply_filters( 'clpr_email_admin_coupons_expired', $email );

        appthemes_send_email( $email['to'], $email['subject'], $email['message'] );
    }
}
add_action( 'clpr_coupon_prune', 'clpr_coupon_prune' );


/**
 * Schedules a daily event to prune coupons which have expired.
 *
 * @return void
 */
function clpr_schedule_coupon_prune() {
    if ( ! wp_next_scheduled( 'clpr_coupon_prune' ) ) {
        wp_schedule_event( time(), 'daily', 'clpr_coupon_prune' );
    }
}
add_action( 'init', 'clpr_schedule_coupon_prune' );

Really would appreciate some help and some input how to fit this problem. Just cant understand why Wordpress 5.1 is not running the cron job!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745675152a4639640.html

相关推荐

  • wp query - cron job for custom post type not working since Wordpress 5

    Since Wordpress 5.1 (or 5 in general) I have a problem with a cron job.This cron top is filtering expired custom posts (

    5小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信