Support

Account

Home Forums Front-end Issues Conditional Logic not working in Front-End Reply To: Conditional Logic not working in Front-End

  • There no direct errors on the site….
    My Function.php afc part

    function my_pre_save_post( $post_id )
    {
        // check if this is to be a new post
        if( $post_id != 'new' )
        {
            return $post_id;
        }
     
        // Create a new post
        $post = array(
            'post_status'  => 'draft' ,
            'post_title'  => 'A title, maybe a $_POST variable' ,
            'post_type'  => 'post' ,
        );  
     
        // insert the post
        $post_id = wp_insert_post( $post ); 
        $targetCatgogry = array( 4 ); 
        wp_set_post_terms( $post_id, $targetCatgogry);
        // update $_POST['return']
        $_POST['return'] = add_query_arg( array('post_id' => $post_id), $_POST['return'] );    
     
        // return the new ID
        return $post_id;
    }
     
    add_filter('acf/pre_save_post' , 'my_pre_save_post' );
    

    My template page php afc

    <?php
    acf_form_head();
    the_post();
    
    $args = array
    (
    	'post_id' => 'new',
    	'field_groups' => array(182, 368)
    );
    
    acf_form( $args ); 
    ?>