Problem with checked box on wp car manager plugin
Question
Hi i have a problem with wp car manager plugin. When the featured and sold checkbox are checked, when you try to uncheck and update the post type content, the checkbox always remain checked.
Any idea to sole this?
Thanks
/**
* Actual meta box output
*
* @param WP_Post $post
*/
public function meta_box_output( $post ) {
// nonce
$this->output_nonce();
// vehicle
$vehicle = wp_car_manager()->service( 'vehicle_factory' )->make( $post->ID );
// load view
wp_car_manager()->service( 'view_manager' )->display( 'meta-box/mb-data', array(
'mb_prefix' => 'wpcm-ld',
'vehicle' => $vehicle,
'fields' => array(
'featured' => array(
'type' => 'checkbox',
'label' => __( 'Featured', 'wp-car-manager' ),
'key' => 'featured',
'required' => false
),
'sold' => array(
'type' => 'checkbox',
'label' => __( 'Sold?', 'wp-car-manager' ),
'key' => 'sold',
'required' => false
),
)
) );
}
/**
* Triggered on save_post
*
* @param int $post_id
* @param WP_Post $post
*/
public function save_meta_box( $post_id, $post ) {
// check if we should save
if ( true !== $this->should_save( $post ) ) {
return;
}
// save
if ( isset( $_POST['wpcm-ld'] ) && count( $_POST['wpcm-ld'] ) > 0 ) {
foreach ( $_POST['wpcm-ld'] as $key => $val ) {
update_post_meta( $post->ID, 'wpcm_' . $key, $val );
}
// set sold to 0 if not set (checkbox)
if ( ! isset( $_POST['wpcm-ld']['sold'] ) ) {
update_post_meta( $post->ID, 'wpcm_sold', '0' );
}
// set featured to 0 if not set (checkbox)
if ( ! isset( $_POST['wpcm-ld']['featured'] ) ) {
update_post_meta( $post->ID, 'wpcm_featured', '0' );
}
// call for update of vehicle order here
$vehicle_manager = new VehicleManager();
$vehicle_manager->update_vehicle_order( $post->ID );
}
}
}
0
2 months
0 Answers
4 views
0
Leave an answer
You must login or register to add a new answer .