[wordpress][solution] Use Gravityforms to add pages instead of posts


min read


As you all know I love GravityForms to make dynamic contactforms.
http://www.gravityforms.com/ > [url=http://gravityforms.ramonfincken.com][u:606207b995]Buy it here(affil)[/u:606207b995][/url]

You can also use GravityForms to add posts, but today I needed to add pages.

Using this simple code ( http://www.ramonfincken.com/permalink/topic184.html ) you can alter the normal way resulting in a page instead of a post.

[b:606207b995]Warnings: [/b:606207b995]
* this will ALWAYS add a page instead of a post when using the post fields in the form configuration.
* you can still use categories, and tags, however you will need to have some PHP skills to show them on your site

[b:606207b995]Best solution, using filters:[/b:606207b995]

Use this in a plugin or your theme functions.php, you only need to adjust the define value (currently = 2) to match your form ID


add_filter("gform_post_data_".MY_FORM_POST_ID, "my_form_change_postdata");



* Changes insert of gravityforms from post to page

* @author Ramon Fincken http://www.ramonfincken.com/permalink/topic217.html

* @param array $post_data

* @param unknown_type $form

* @param unknown_type $lead


function my_form_change_postdata($post_data , $form, $lead)


$post_data[’post_type’] = ‘page’;

return $post_data;


[b:606207b995]OLD SOLUTION, this is a hack and not recommended[/b:606207b995]
Now it was easy:
$post_id = wp_insert_post($post_data);

// Ramon Fincken’s hack to add a page instead of a post http://www.ramonfincken.com/permalink/topic217.html
$post_data[’post_type’] = ‘page’;

http://www.gravityforms.com/ > [url=http://gravityforms.ramonfincken.com][u:606207b995]Direct download (affil)[/u:606207b995][/url]

Leave a Reply

Your email address will not be published. Required fields are marked *