Support

Account

Home Forums Front-end Issues acf_form, new_post, tax_input requires to be logged in Reply To: acf_form, new_post, tax_input requires to be logged in

  • This solution didn’t work for me. I made the post author id 1 or the admin and got the same result AFTER spending a LONG time trying to make my “guest author” have the right capabilities without success. I am using CPT UI to make my taxonomies and post types. For not logged in users save_post was my solution…

    Make your own inputs with whatever values you want:

    $htmlAfter = '<input type="hidden" name="tax_name" id="tax_name" value="ENTER_MAIN_TAXONOMY_SLUG">';
    $htmlAfter .= '<input type="hidden" name="tax_slug" id="tax_slug" value="ENTER_INDIVIDUAL_TAXONOMY_SLUG">';

    Add those inputs to acf_form function with html_after_fields parameter (or html_before_fields):

    'html_after_fields' => $htmlAfter

    Save those values ($_POST) as you wish with save_post action:

    function my_acf_save_post( $post_id ) {
        
       if(isset($_POST['tax_name']) && isset($_POST['tax_slug'])) {
    	 wp_set_object_terms( $post_id, $_POST['tax_slug'], $_POST['tax_name'], true );
    	}
        
    }
    
    // run after ACF saves the $_POST['acf'] data
    add_action('acf/save_post', 'my_acf_save_post', 20);