if statement not working in save_post
-
I have added a simple meta box, that is working properly, and when I save/update a post, I want to do something with the content UNLESS this box is checked.
My save_post is like this:
add_action( 'save_post', 'ac_check_link' ); function ac_check_link($post_id) { remove_action( 'save_post', 'ac_check_link' ); update_post_meta( $post_id, 'ac_link_checkbox', $_POST['ac_link_checkbox']); if ($_POST['ac_link_checkbox'] != "no") { $post = get_post( $post_id ); $content = $post->post_content; // do stuff wp_update_post( [ 'ID' => $post_id, 'post_content' => $content ] ); } add_action( 'save_post', 'ac_check_link' ); }
Regardless if the checkbox is selected or not, everything inside the if runs. I tried getting the meta data with get_post_meta but it also doesn’t work.
if I var_dump and exit the if statement, in the network when I try to update I see that the request in “wp-json/wp/v2/posts/64?_locale=user” returns true and “wp-admin/post.php?post=64&action=edit” returns false, but I don’t know what this means.
Any idea how I can make this work? Thanks!
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘if statement not working in save_post’ is closed to new replies.