Support

Account

Home Forums Front-end Issues Set title on acf_form

Solving

Set title on acf_form

    • gab1982

    • January 7, 2021 at 1:23 am

    Hi I have tried to set a title for an acf_form I have in a page template but no title is showing in the admin, this is my code:

    <?php
    						$args = array(
    							'post_id' 	   => "new_post",
    							'field_groups' => array(62),
    							'updated_message' => false,
    							'new_post'		=> array(
    								'post_title'   => $_POST['acf']['field_5ff5921bc7f1c'] . " - " . $_POST['acf']['field_5ff59276c7f1d'] . "Date:" . $_POST['acf']['field_5ff5869624818'] . "-" . $_POST['acf']['field_5ff586ba24819'],
    								'post_type'		=> 'loads',
    								'post_status'	=> 'draft'
    							),
    							'submit_value' => __("Register", 'acf')
    					
    						);
    						
    						acf_form($args); ?>

    The only part being set as the title is ‘Date:’ which is hard coded. Can anyone help.

    • moscato

    • March 24, 2021 at 4:12 pm

    As an example, this will set the post title on save or update from input fields.

    <?php // SET TITLE ON SAVE & UPDATE
    function my_post_title_updater($post_id) {
    	if ( get_post_type( $post_id ) == 'account' ) {
    		$my_post = array(
    			'ID'           => $post_id,
    			'post_title'   => get_field( 'last_name', $post_id ) . ', ' . get_field( 'first_name', $post_id ),
    		);
    		wp_update_post( $my_post );
    	}
    }
    add_action('acf/save_post', 'my_post_title_updater', 20); // run after ACF saves the $_POST['fields'] data
    ?>
  • $_POST[‘acf’][‘field_5ff5921bc7f1c’] has no value when acf_form() is called. If you want to set the post title based on fields that are being submitted then you need to do this after the post is created using an acf/save_post action.

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.