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


acf_form, new_post, tax_input requires to be logged in

  • I’ve been baffled with a mystery why doesn’t submission of a post from the frontend work when a normal user does it. The following code works perfect (it’s part of acf_form function) when I’m logged in but it doesn’t work otherwise.

    'new_post'		=> array(
    						'post_type'		=> 'my_custom_post_name',
                'post_status'    => 'pending',
                'tax_input'  => array('my_custom_taxonomy' => array(82)),
                'post_author'    => 6

    Turns out, it seems that the problem is tax_input as described here:

    “It turns out that ‘tax_input’ does not work if a user does not have the capabilities to work with a custom taxonomy.”

    Is there anyway to get this to work for all users…

  • Actually I solved this now.

    post_author (id 6) here is a specific user account for front end posting. I increased it’s capabilities to handle taxonomies and all is well now.

  • 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);
Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘acf_form, new_post, tax_input requires to be logged in’ is closed to new replies.