|
|
View previous topic
::
View next topic
|
Author |
Message |
ramon fincken Site's programmer
 Get a free globally recognized avatar It's free!
Joined: 03 Aug 2007 Posts: 412 Location: A'dam/Diemen, The Netherlands
|
Posted: Sat Jun 05, 2010 3:29 pm Post subject: [wordpress][solution] Use Gravityforms to add pages instead of posts |
|
|
As you all know I love GravityForms to make dynamic contactforms.
http://www.gravityforms.com/ > Buy it here(affil)
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.
Warnings:
* 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
Best solution, using filters:
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
define('MY_FORM_POST_ID',2);
Code: | define('MY_FORM_POST_ID',2);
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;
} |
OLD SOLUTION, this is a hack and not recommended
Now it was easy:
Code: | FIND
$post_id = wp_insert_post($post_data);
BEFORE, ADD
// 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/ > Direct download (affil) |
|
Back to top |
|
 |
Google adsense Advertisement
|
Posted: Sat Jun 05, 2010 3:29 pm Post subject: [wordpress][solution] Use Gravityforms to add pages instead of posts |
|
|
Advertisement
|
|
Back to top |
|
 |
GravityForms Advertisement
|
Posted: Sat Jun 05, 2010 3:29 pm Post subject: [wordpress][solution] Use Gravityforms to add pages instead of posts |
|
|
Advertisement
 |
|
Back to top |
|
 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|