I'm writing a WordPress plugin and have a checkbox in a form.
If the checkbox is checked it saves the value to the database and shows up checked in the form. However if the checkbox is checked it outputs checked='checked'
in the form.
So the checkbox works like it needs to work but I cant see why it outputs checked='checked'
to the form
public function display() {
$html = '';
// Add an nonce field so we can check for it later.
wp_nonce_field( basename( __FILE__ ), 'nonce_check_value' );
$html .= '<label for="CMBUserBoxName">Name metabox: </label>';
$html .= '<input type="text" name="CMBUserBoxName" value="' . get_post_meta( get_the_ID(), 'CMBUserBoxName', true ). '">';
$html .= '<h1>What do you need?</h1>';
$html .= '<label for="CMBUserCheckbox">Checkbox: </label>';
$checkedByUser = get_post_meta( get_the_ID(), 'CMBUserCheckbox', true );
$html .= '<input type="checkbox" name="CMBUserCheckbox" value="1" '.checked( $checkedByUser, 1 ).' />';
echo $html;
}
The output on screen is as followed
Aucun commentaire:
Enregistrer un commentaire