Friday, February 17, 2023
HomeWordPress Developmentphp - Learn how to update_post_meta checkbox if physique has particular class

php – Learn how to update_post_meta checkbox if physique has particular class


I’ve a metabox checkbox and need to set it checked if the physique has a particular class.

I attempted one thing like this:

$courses = get_body_class();
if (in_array(‘datesconfirmed’,$courses)) {
update_post_meta( $post_id, ‘_showdates_meta_key’, $_POST[‘showdates_field’][1] );
}

however its not working. solely with admin physique class not with the entrance finish physique class.


perform showdates_metabox_content($submit) {

    $worth = get_post_meta($post->ID, '_showdates_meta_key', true) ? 'checked' : '';    
    ?>   
    <enter kind="checkbox" identify="showdates_field" id="showdates_field" class="datescheckbox" <?php echo $worth; ?>>
    <label for="showdates_field"> Present Dates</label> 
      
    <?php
}
perform showdates_save_postdata($post_id) {
    if (array_key_exists('showdates_field', $_POST)) {
        update_post_meta( $post_id, '_showdates_meta_key', $_POST['showdates_field'] );
    } else {
        delete_post_meta( $post_id, '_showdates_meta_key' );
    }  
}
add_action('save_post', 'showdates_save_postdata',2,3);

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments