通过快速编辑更新 Woocommerce 产品描述

问题描述 投票:0回答:1

我正在向 WordPress 的快速编辑区域添加一些功能。除了更新 post_content 之外,我一切正常。我可以使用 update_post_meta 更新元值,但我用来更新 post_content 的方法只会导致无限旋转的轮子。

function min_max_step_desc_quick_edit_save( $post_id, $post ){

    // check inlint edit nonce
    if ( ! wp_verify_nonce( $_POST[ '_inline_edit' ], 'inlineeditnonce' ) ) {
        return;
    }

    // update the price
    $min = ! empty( $_POST[ 'min' ] ) ? absint( $_POST[ 'min' ] ) : '';
    update_post_meta( $post_id, '_alg_wc_pq_min', $min );

    $max = ! empty( $_POST[ 'max' ] ) ? absint( $_POST[ 'max' ] ) : '';
    update_post_meta( $post_id, '_alg_wc_pq_max', $max );
    
    $step = ! empty( $_POST[ 'step' ] ) ? absint( $_POST[ 'step' ] ) : '';
    update_post_meta( $post_id, '_alg_wc_pq_step', $step );
    
    $desc = ! empty( $_POST[ 'desc' ] ) ? absint( $_POST[ 'desc' ] ) : '';
    $my_post = array();
        $my_post['ID'] = $post_id;
        $my_post['post_content'] = $desc;
        wp_update_post( $my_post );
}
php wordpress woocommerce product
1个回答
0
投票

尝试通过执行以下操作来减少错误:

function min_max_step_desc_quick_edit_save( $post_id, $post ) {
    // Update post
    $my_post = array(
        'ID'           => $post_id,
        'post_title'   => 'This is the post title.',
        'post_content' => 'This is the updated content.',
    );

    // Update the post into the database with $wp_error to true
    wp_update_post( $my_post, true );

    // Of course, this should be done in an development environment only and commented out or removed after deploying to your production site.                
    if ( is_wp_error( $post_id ) ) {
        $errors = $post_id->get_error_messages();
        foreach ($errors as $error) {
            echo $error;
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.