Home Forums ACF PRO Uncheck checkbox programmatically Reply To: Uncheck checkbox programmatically

  • Hi John,
    I’m using a checkbox. But the main issue I found over the weekend seems to be, that I hook into post transition status. That seems to fire PRIOR to saving fields. So, the check I do in “sendPublishNewseletter” -> “if(get_field(“send_newsletter”,$postid))” first of all is only true, if the checkbox was saved before. So I guess the “update_field(“send_newsletter”,0,$postid);” function does nothing, as it does not save to the database???

    See my full code below.

    Thanks Sascha

    P.S.: I try to send a newsletter out, when the post is published. This is done by the “do_action(news_publish)” found later in the code.

    /* Add Newsletter Action Hook on Publish */
    add_action('transition_post_status', 'send_new_post', 10, 3);
    // Listen for publishing of a new post
    function send_new_post($new_status, $old_status, $post) {
      if('publish' === $new_status && 'publish' !== $old_status && $post->post_type === 'post') {
    //sending function
    function sendPublishNewseletter($postid){
    		//uncheck field
    		//define post ID
    		$sendoutID = $postid;
    		//get files
    		$downloadHTML ='';
    		if(get_field("dateien",$sendoutID)) { 
    				$downloadHTML .= '<div style="margin: 20px; border: 1px solid #000; border-radius: 3px; background-color: #ECECEC;"><div style="margin: 20px; "><h3>Dokumente zum Download</h3>';
    				foreach(get_field("dateien",$sendoutID) as $singleFile) {
    					$thumbnailURL = '/wp-includes/images/media/document.png';
    					$downloadHTML .= '<a href="'.$singleFile['datei']['url'].'" class="textlink" download>'.$singleFile['datei']['title'].' ('.pathinfo($singleFile['datei']['url'],PATHINFO_EXTENSION).', '.size_format($singleFile['datei']['filesize']).')</a><br/>';
    				$downloadHTML .= '</div></div>';
            do_action( 'news_publish','', array( 
    			'teaser-subject' => '{post_title:'.$sendoutID.'}',
    			'teaser-date' => get_the_date( 'd.m.Y', $sendoutID ),
    			'teaser-image' => get_the_post_thumbnail_url($sendoutID),
    			'teaser-link' => '{post_link:'.$sendoutID.'}',
    			'teaser-content' => '{post_content:'.$sendoutID.'}',
    			'teaser-downloads' => '<div style="text-align: center;">'.$downloadHTML.'</div>',