I'm adding some features to the quck edit area of wordpress. I have everything working except updating post_content. I am able to update the meta values using update_post_meta, but the method I'm using to update post_content just causes the infinite spinning wheel.
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 );
}
As this is for WooCommerce Products Quick Edit, you can use the following instead:
// Save quick edit custom fields values
add_action( 'woocommerce_product_quick_edit_save', 'min_max_step_desc_quick_edit_save' );
function min_max_step_desc_quick_edit_save( $product ){
$updated = false;
if ( isset($_REQUEST['min']) ) {
$product->update_meta_data('min', (!empty($_REQUEST['min']) ? intval($_REQUEST['min']) : ''));
$updated = true;
}
if ( isset($_REQUEST['max']) ) {
$product->update_meta_data('max', (!empty($_REQUEST['max']) ? intval($_REQUEST['max']) : ''));
$updated = true;
}
if ( isset($_REQUEST['step']) ) {
$product->update_meta_data('step', (!empty($_REQUEST['step']) ? intval($_REQUEST['step']) : ''));
$updated = true;
}
// For the product description ("post_content")
if ( isset($_REQUEST['description']) ) {
$product->set_description(!empty($_REQUEST['description']) ? sanitize_text_field($_REQUEST['description']) : '');
$updated = true;
}
// Save updated product data and metadata to database
if ( $updated ) {
$product->save(); // save product meta data
}
}
It should work.