Here's my problem, I allow a certain user type to create custom post type in the front-end of my site, with the
wp_insert_post()
function... users can put values within a form and there's couple of input types, checkboxes, ranges, numbers, and text fields. But I have a problem with checkbox and radio inputs. when users save values, they don't appear in the post in the admin panel, I think the problem is in the
update_post_meta()
condition... here how was the condition:
if( isset( $_POST[ 'checkbox_1' ] ) ) { update_post_meta( $post_id, 'checkbox_1', 'yes' ); }else{ update_post_meta( $post_id, 'checkbox_1', '' ); }
so I changed it like that:
$stored_meta= get_post_meta($post_id); if(isset( $_POST[ 'checkbox_1' ] ) ) { update_post_meta( $post_id, 'checkbox_1', $_POST[ 'checkbox_1' ]) ; }else{ update_post_meta( $post_id, 'checkbox_1', $stored_meta['checkbox_1'][0]); }
Now they appear, but it's impossible to modify them in the admin panel, for example if user checked an input, even if I unchek it, it remains check after update.
I have tried other logic, but they all failed.
here's how look my checkbox input:
<input type="checkbox" name="checkbox_1" value='yes' <?php if ( isset ( $stored_meta['checkbox_1'][0] ) ) checked( $stored_meta['checkbox_1'][0], 'yes'); ?>>
$stored_meta['checkbox_1'][0]
to'no'
?var_dump(get_post_meta($post-ID))
in the admin side,[checkbox_1][0] = 'no'
. however it is a'yes'
which was passed. it's like the post is updated before modification.