Support

Account

Home Forums Front-end Issues Can't get post_title or post_content fields

Solved

Can't get post_title or post_content fields

  • Hi, i’m trying to create new posts from the front end everything works but I can’t get the post title or the post name.
    I red the doc here: http://www.advancedcustomfields.com/resources/acf_form/

    post_title Whether or not to show the post title text field. Defaults to false
    post_content Whether or not to show the post content editor. Defaults to false

    but it didn’t help me :/

    Here is my code, it would really help me if you can take the time to review it.

    Advanced Custom Fields Version 4.3.9

    <?php 
    
    			function my_pre_save_post( $post_id )
    {
        // Create a new post
        $post = array(
            'post_status'  => 'publish' ,
            'post_type'  => 'person' ,
        );  
    
        // insert the post
        $post_id = wp_insert_post( $post ); 
    
        // update $_POST['return']
        $_POST['return'] = add_query_arg( array('post_id' => $post_id), $_POST['return'] );    
    
        // return the new ID
        return $post_id;
    }
    
    add_filter('acf/pre_save_post' , 'my_pre_save_post' );
    
    acf_form_head(); ?>
    <?php
    /**
     * Template Name: Add a person
     *
     * Description: Twenty Twelve loves the no-sidebar look as much as
     * you do. Use this page template to remove the sidebar from any page.
     *
     * Tip: to remove the sidebar from all posts and pages simply remove
     * any active widgets from the Main Sidebar area, and the sidebar will
     * disappear everywhere.
     *
     * @package WordPress
     * @subpackage Twenty_Twelve
     * @since Twenty Twelve 1.0
     */
     
    
    get_header(); ?>
    
    	<div id="primary" class="site-content">
    		<div id="content" role="main">
    			<h1>Add a person:</h1>
    			<br /> 
    	<div id="primary">
    		<div id="content" role="main">
    
    			<?php 
    
    			$args = array(
    				'post_id' => 'new',
    				'field_groups' => array(6),
    				'post_type'		=> 'person',
    				'post_title'	=> true,
    				'post_content'	=> true			
    				);
    
    			acf_form( $args ); 
    
    			?>
    		</div><!-- #content -->
    	</div><!-- #primary -->
    
    <?php get_footer(); ?>

    Thank you very much for your help 🙂

  • First of all, you should stick your function at the top in functions.php

    But to answer your question, the post_title and post_content settings are only available in ACF 5. When you look at that tutorial, make sure you’ve selected “Version 4” at the top. But more importantly, I’d suggest you upgrade to ACF 5 to do more advanced front-end forms.

  • Thanks bought it 😉 (not with this account)

  • I found this fellas great solution.

    http://wordpress.stackexchange.com/questions/9912/front-end-post-editing-using-a-form

    However it is for v4. I made a pretty little change, then everything works fine:
    add_action(‘acf/include_fields’, ‘my_register_fields’);

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Can't get post_title or post_content fields’ is closed to new replies.