wp_update_post正在重复我的帖子

时间:2015-12-01 21:11:47

标签: wordpress wp-query

我有这个功能,如果它有两个元值,则可以更改自定义帖子类型的帖子状态。现在,如果它匹配这两个值而不是仅仅更改状态,它会创建2个新帖子,将它们设置为新的post_status,并使原始帖子保持原始状态。

这是我正在使用的功能:

function set_reg_emails(){
    wp_reset_postdata();
                $regargs = array (
    'nopaging'               => true,
    'post_type'              => 'trip_reg',
    //'fields'               => 'ids',
    'post_status'            => 'draft'
);

// The Query
$the_reg_query = new WP_Query( $regargs );
if ( $the_reg_query->have_posts() ) {

    while ( $the_reg_query->have_posts() ) {
        $the_reg_query->the_post();
        $send_email = 'no';
        $reg_basic_form = get_post_meta( $the_reg_query->post->ID, 'reg_basic_form', true );
        $reg_medical_form = get_post_meta( $the_reg_query->post->ID, 'reg_basic_form', true );
        $reg_trip_id = get_post_meta( $the_reg_query->post->ID, '__relate_post', true );
        $reg_trip_beg_date = get_post_meta( $reg_trip_id, 'trip_begin', true );
        $prayer_title= get_the_title();
        $reg_userdata = get_userdata(get_post_meta( $the_reg_query->post->ID, 'reg_user', true ));
        $reg_author  = get_userdata(get_the_author_meta('ID'));
        //$prayer_edit_link = admin_url( 'post.php?post=' . $the_reg_query->post->ID . '&action=edit');
        if($reg_basic_form == "True" && $reg_medical_form == "True"){
             if ( ! wp_is_post_revision( $the_job_query->post->ID ) ){
                 $my_new_post = array();
                 $my_new_post['ID'] = $the_job_query->post->ID;
                 $my_new_post['post_status'] = 'approved';
            wp_update_post( $my_new_post );
             }
            goto skipemail;
        }


     skipemail:  
    }
}
wp_reset_postdata();
}

1 个答案:

答案 0 :(得分:0)

我意识到我错过了引用ID。

我把the_job_query而不是the_reg_query