Saturday, October 6, 2012

Wordpress front end editor

Ever got a requirement of retrieving customer submitted data and storing it into your post, page or custom post type in Wordpress.

Well, there is a simple editor function wp_editor() is available within wordpress.


Just put the following code, wherever you want to insert editor in the front end.

<?php
if($_POST['submit'])
{
print_r($_POST);
}
echo '<form action="" method="post">'; // Insert form to grab post data
wp_editor('<p>Hello</p>', 'textarea01' );
echo '<input type="submit" name="submit" value="Submit" /></form>' // Button to submit the data
?>


You can insert any number of text fields to let user submit all the data regarding the particular post type. For example, you can also insert text input field for the title field of the post and another field for modifying the slug.

It 's upto you now, how you can take advantage of this simple editor interface on the front end.

Further, you can use wp_insert_post() function to insert new post into the wordpress.

<?php wp_insert_post( $post, $wp_error ); ?> 

For more information on wp_insert_post() refer http://codex.wordpress.org/Function_Reference/wp_insert_post

1 comment:

  1. Thank you for your informative article. Please add some more related subjects to the discussion. We've come to read your blog because, as you know, there's no other reason for us to be here. Well, if you get time, you must checkout my website DedicatedHosting4u.com

    ReplyDelete