Home Forums ACF PRO ACF_Form – Default taxonomy via 'tax_input' without increasing permissions Reply To: ACF_Form – Default taxonomy via 'tax_input' without increasing permissions

  • Wanted to give some help. I was stuck on this part for a while to. When you use acf_form() you NEED acf_form_header() FOR SURE if the person is not logged in (unsure about admins logged in)… BUT the save_post method is good. It ISN’T capabilities that is messing it up. I tested to be sure by making the author in acf_form() be the admin (all capabilities) and that didn’t solve the problem. So the save post method is the best BUT then it is hard to get OTHER variables outside the post you created (like from the page you used acf_form() on etc):

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

    Then include it in the acf_form() via the parameter “html_after_fields”:

    'html_after_fields' => $htmlAfter

    THEN, the save_post function:

    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);

    You could enter the values for taxonomy and slug manually or set them as variables conditionally based on whatever you want, where ever you include acf_form() …