Support

Account

Home Forums Front-end Issues Selecting Category from Frontend Form Reply To: Selecting Category from Frontend Form

  • Function.php

    
    function acf_review_before_save_post($post_id) {
    	if (empty($_POST['acf']))
    		return;
    	$_POST['acf']['_post_title'] = $_POST['acf']['field_558eb15c51fc7'];
    	$_POST['acf']['_post_content'] = $_POST['acf']['field_558eb19c51fc8'];
    	$_POST['acf']['_post_category'] = $_POST['acf']['field_55d73c0ee19e4'];
    	return $post_id;
    }
    add_action('acf/pre_save_post', 'acf_review_before_save_post', -1);
    

    Template for page with form

    <?php acf_form(array(
     'post_id'	=> 'new_post',
     'new_post'	=> array(
       'post_type'	=> '',
       'post_status'=> 'publish',
       'post_title'  => $_POST['acf']['field_558eb15c51fc7'], // Post Title ACF field key
       'post_content'  => $_POST['acf']['field_558eb19c51fc8'], // Post Content ACF field key
       'post_category' => $_POST['acf']['field_55d73c0ee19e4'], // Post Category ACF field key
    ),
       'field_groups'   => array(317), // Create post field group ID(s)
       'form'               => true,
    //'return'             => '%post_url%', // Redirect to new post url
       'html_before_fields' => '',
       'html_after_fields'  => '',
       'submit_value'       => 'Submit Post',
       'updated_message'    => 'Saved!',
        'uploader' 			 => 'wp',
        'return' 		=> '/'
       )); ?>