Top Poster
#1 ramon fincken 399
#2 Site admin 3
#3 Ber|Art 2
#4 braddmark 1
#5 accentmedia 1
#6 Xarzu 1
#7 pEcosespedex 1
#8 khadish 1
#9 moxxx 1
#10 nistelrock 1
[wordpress][solution] Use Gravityforms to add pages instead of posts



Rating : 4.5 / 5

 
Post new topic   Reply to topic    Ramonfincken.com Forum Index -> CMS-ses (Joomla, WordPress, etc..)
Beta
Want to be notified by email when this topic gets a reply?  
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: 399
Location: A'dam/Diemen, The Netherlands

PostPosted: Sat Jun 05, 2010 3:29 pm    Post subject: [wordpress][solution] Use Gravityforms to add pages instead of posts Reply with quote

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
View user's profile Send private message Visit poster's website
Google adsense
Advertisement





PostPosted: 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





PostPosted: Sat Jun 05, 2010 3:29 pm    Post subject: [wordpress][solution] Use Gravityforms to add pages instead of posts

Advertisement
Gravity Forms Plugin for WordPress
Back to top
Post new topic   Reply to topic    Ramonfincken.com Forum Index -> CMS-ses (Joomla, WordPress, etc..) All times are GMT
Page 1 of 1

 
Jump to:  
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
General forums
The world of freelance
Programming
Other projects
Poll
I love gifts

Yes goodies and presents! [3]
No but I love polls ! [1]

Related google ads