The gform_advancedpostcreation_post filter allows you to modify the Post object before it is created in Gravity Forms.
Usage
A generic example of how to use the filter for 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 (array): The post object to be created.
- $feed (Feed Object): The current feed object.
- $entry (Entry Object): The current entry object.
- $form (Form Object): The current form object.
More information
See Gravity Forms Docs: gform_advancedpostcreation_post
Examples
Change the post content
Modify the post content before it’s created:
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
Use merge tags to change the post slug (post_name property) for form id 1:
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
Use a specific paragraph field as the post excerpt (replace 6 with your field id):
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.