gform_advancedpostcreation_post

Description

Modifies the Post object before it is created.

Note: This filter should not be used to override the Post ID value. Doing it would cause unexpected results during the Post creation process.

Usage

The following would apply to all forms:

add_filter( 'gform_advancedpostcreation_post', 'your_function_name', 10, 4 );

To target a specific form, append the form id to the hook name. (format: gform_advancedpostcreation_post_FORMID)

add_filter( 'gform_advancedpostcreation_post_1', 'your_function_name', 10, 4 );

Parameters

  • $post bool
    The post object to be created.
Array
    (
        [post_status] => publish
        [post_type] => post
        [post_title] => testing
        [comment_status] => closed
        [ping_status] => closed
        [ID] => 328
        [post_content] => test,test, test, test,
        [post_excerpt] => Excerpt Test
        [post_author] => 1
        [post_date_gmt] => 2019-04-30 20:40:00
    )

Examples

Change the post content

add_filter( 'gform_advancedpostcreation_post', 'change_post', 10, 4 );
function change_post( $post, $feed, $entry, $form){
	$post['post_content'] = 'This is a test';
	return $post;
}

Change the post slug

This example uses merge tags to change the post slug which is taken from the post_name property. This time we have limited the scope of the snippet to form id 1 by adding the form id to the filter name.

add_filter( 'gform_advancedpostcreation_post_1', function ( $post, $feed, $entry, $form ) {
	$slug = '{first name:1.3} {last name:1.6} {date:2:year}-{date:2:month}';
	$post['post_name'] = sanitize_title( GFCommon::replace_variables( $slug, $form, $entry, false, false, false, 'text' ) );
	return $post;
}, 10, 4 );

Change the post excerpt

This examples uses a specific paragraph field to be written to the post excerpt. Be sure to change your code to match the field id which you are using for inputting the excerpt.

add_filter( 'gform_advancedpostcreation_post', 'change_post_excerpt', 10, 4 );
function change_post_excerpt( $post, $feed, $entry, $form){
    $post['post_excerpt'] = rgar( $entry, 6 ); // Field 6 is the Excerpt
    return $post;
}

Placement

This code should be placed in the functions.php file of your active theme.

Since

This filter was added in the Gravity Forms Advanced Post Creation add-on version 1.0.

Source Code

This filter is located in GF_Advanced_Post_Creation::create_post() in class-gf-advancedpostcreation.php.