I have two checkboxes on a post and I’m looking for a way to check a selected box when saving a post.
The two checkboxes are under ‘status_active’ and the checkbox is called ‘status_locked’ and I’m looking for a way to check ‘status_locked’ in ‘status_active’ when saving the post.
I guess the best way would be to update the field and save it as ‘TRUE’?
Code so far:
function post_extra_save( $post_id, $post){
global $pagenow;
if ($pagenow == 'post.php') {
if (! in_array( 'status_locked', get_field('status_active', $post_id) )) {
};
};
add_action( 'save_post', 'post_extra_save', 10, 2 );
It it is a checkbox field then you need to update it with an array of the values you want checked, each value is not stored separately.
$status_active = get_field('status_active', $post_id);
if (!in_array('status_locked', $status_active)) {
$status_active[] = 'status_locked';
update_field('status_active', $status_active, $post_id);
};
What if there’s multiple choices?
$status_active = get_field('breaking_news_status', $post_id) == 'active';
if (!in_array('breaking_news_status', $status_active)) {
$status_active[] = 'status_locked';
update_field('breaking_news_status', $status_active, $post_id);
};
never mind, figured it out