如果条件为真,则将wordpress post更新为draft

时间:2017-03-26 12:07:46

标签: php wordpress advanced-custom-fields

我使用以下代码从ACF转发器字段中删除具有过期日期的行,当行数达到零时,将帖子更新为草稿模式或私有模式。 但有些事情并不令人担忧(草案不起作用。)

$ap = get_post_meta($post->ID,'sub_seminars_0_start_date',true);
$startdate = date("Ymd", strtotime($ap));
$todaydate = date("Ymd");
if(strtotime($todaydate) > strtotime($startdate) && !empty($ap)){
    $del_data = array(
                    'Ref' => 'sub_seminars_0_ref',
                    'Start date' => 'sub_seminars_0_start_date',
                    'End Date' => 'sub_seminars_0_end_date',
                    'Venue' => 'sub_seminars_0_venue',
                    'Fees' => 'sub_seminars_0_fees',
                    'CPE Credits' => 'sub_seminars_0_cpe_credits'
        );
    delete_row('sub_seminars', 1);
    $row = count( get_field('sub_seminars') );
    if ($row == 0) {
        $postid = $post->ID; //Supply post-Id here $post->ID.
        wp_update_post(array(
            'ID'    =>  $postid,
            'post_status'   =>  'draft'
        ));

    }
}

任何人都可以告诉我有什么问题以及如何解决它?

1 个答案:

答案 0 :(得分:1)

 $rows = get_field('sub_seminars');
         $row_count = count($rows);
       // $row_count = count($rows);
        if ($rows == 0) {
           $my_post = array(
               'ID'     => $post->ID,
               'post_status'   =>  'draft'
                );
                wp_update_post($my_post);
            } 

使用上面的代码解决了我的问题。