• Just bought the pro version – the plugin is impressive! Nice Job!

    I would like to set the new post name (which is created successfult),
    to have the same value as in a field within the (only) Field Group that I am using.

    There is an option for shortcode.
    But how do I use it.

    The needed field value is mandatory so it will have a value upon submitting.

    Can the shortcode help?
    Thanks

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter mulli.bahr

    (@mullibahr)

    Ugly workaround:

    
    // After save post
    add_action('acf/save_post', 'my_acf_save_post', 30);
    function my_acf_save_post( $post_id ) {
       // Following keys are FG name and user defined id name
       // Both are "hard" constants
        $title = $_POST['acf']['field_5f3a38f2a4c08']['field_5f3a3939a4c09'];
        error_log('acf after save_post  title='. $title);
    
        $my_post = array(
              'ID'           => $post_id,
              'post_title'   => $title
          );
     
    // Update the post title into the database
        wp_update_post( $my_post, true );
        
        if (is_wp_error($post_id)) {
            $errors = $post_id->get_error_messages();
            foreach ($errors as $error) {
                echo $error;
            }
        }
      
    }
    
    • This reply was modified 4 years, 7 months ago by mulli.bahr.

    I’ll be using this until more info on default post title is provided! Thanks for this!

    Actually, I made this a little less ugly (and with no error logging):

    // After save post
    add_action('acf/save_post', function ( $post_id ) {
    	$values = get_fields( $post_id );
    	extract( $values );
    	$my_post = array(
    		'ID'           => $post_id,
    		'post_title'   => "{$first_name} {$last_name}, {$city}, {$state}" 
    	);
    
    	// Update the post title into the database
    	wp_update_post( $my_post, true );  
    }, 10, 1 );
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to use shortcode for new post title?’ is closed to new replies.