Support

Account

Home Forums Front-end Issues acf_form NOT creating new Post Reply To: acf_form NOT creating new Post

  • I’ve decided to come at this from a different angle and found a solution. All I need to save is the Post Title and Post Content which is really simple to do with v5 acf_form. But I want to use a “Basic” wysiwyg editor and remove the ability to upload media.

    Here is the solution I came up with

    Here is the code on the Create Post page template:

    acf_form( array(
    	'post_id' => 'new_post',
    	'new_post' => array(
    		'post_status' => 'publish',
    		'post_type' => 'post',
    		'post_title' => $_POST['acf']['_post_title']
    	),
    	'post_title' => true,
    	'post_content' => true,
    	'submit_value' => __('Publish', 'ppt-church'),
    	'updated_message' => __('Your post has been published', 'ppt-church')
    ));

    Here is the code on the Edit Post page template:

    $post_id = $_GET['post_id'];
    acf_form( array(
    	'post_id' => $post_id,
    	'post_title' => true,
    	'post_content' => true,
    	'submit_value' => __('Update Post', 'ppt-church'),
    	'updated_message' => __('Your post has updated', 'ppt-church')
    ));

    I use $_GET to get the post ID from the URL

    Here is the code in the functions.php file:

    // Change Post Content Type
    add_filter( 'acf/get_valid_field', 'change_post_content_type');
    function change_post_content_type( $field ) {
    		
    	if($field['type'] == 'wysiwyg') {
    		$field['tabs'] = 'visual';
    		$field['toolbar'] = 'basic';
    		$field['media_upload'] = 0;
    	}
    		
    	return $field;
    		
    }

    I hope this helps anyone