• Pete

    (@perthmetro)


    Insert this code into functions.php and change the post types accordingly…

    add_action( 'save_post', 'wpse_214927_alter_title', 10, 2 );
    
    add_action( 'wpuf_add_post_after_insert', 'wpse_214927_alter_title', 10, 2 );
    
    add_action( 'wpuf_edit_post_after_update', 'wpse_214927_alter_title', 10, 2 );
    
    function wpse_214927_alter_title ( $post_id, $post_object )
    
    {
    
        // Target only specific post type
    
        if (    'my_specific_post_type'       !== $post_object->post_type
    
             && 'my_other_specific_post_type' !== $post_object->post_type
    
        )
    
            return;
    
        $post_date      = $post_object->post_date;
    
        $format_date    = DateTime::createFromFormat( 'Y-m-d H:i:s', $post_date );
    
        $date_formatted = $format_date->format( 'Y-m-d' ); // Set correct to display here
    
        $post_author    = $post_object->post_author;
    
        $author_name    = get_the_author_meta( 'display_name', $post_author ); // Adjust as needed
    
        $my_post = [
    
            'ID' => $post_id,
    
            'post_title' =>  '#' .  $post_id . ' ' . $author_name  . ' ' . $date_formatted // Change as needed
    
        ];
    
    	// unhook this function so it doesn't loop infinitely
    
    	remove_action('save_post', 'wpse_214927_alter_title');
    
    	wp_update_post( $my_post );
    
    	// re-hook this function
    
    	add_action('save_post', 'wpse_214927_alter_title');
    
    }

    https://wordpress.org/plugins/wp-user-frontend/

  • The topic ‘How to automatically generate a post title in WPUF’ is closed to new replies.