0

I have a CPT and in the columns section, there is a button. I have a checkbox in my custom meta box and it is hidden. But when the checkbox has been clicked the text of the button and color will be different. So, the code is

$topic_checkbox_meta = get_post_meta( $post_id, 'topic_checkbox_value', true );
            $meta = get_post_meta( $post_id );
            $topic_checkbox_value = ( isset( $meta['topic_checkbox_value'][0] ) &&  '1' === $meta['topic_checkbox_value'][0] ) ? 1 : 0;

            if( $topic_checkbox_value == 0 ){
                echo '<button class="btn btn-sm btn-info" id="check-btn-'. $post_id . '"onclick="return checkingFunction('.$post_id.')">Pick</button>';
            }
            else {
                echo '<button class="btn btn-sm btn-warning" >Picked</button>';

            }

But what i want is when the I click the Pick button then I want to update the value from 0 to 1 in the database too. I don't know it's easy or hard but its really important to do that. So, the photo is of the columns section is like this. Photo is like this

So, As you can see if the meta value of the checkbox in 0 then the button will be displayed as Pick but if the it is 1 the it will be Picked and the color will change. So how can I update the meta value if the Pick button is clicked using Javascript or anything. I tried but it is not working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.