WordPress Insert Post from Front End

Hi, In this article I will show one example plugin for making post entry from wordpress front end.

Screenshot:

Below is the sample code for the plugin

<?php
/*
Plugin Name: Insert Post Fontend Demo Plugin
Plugin URI: http://thedigilife.com
Description: Example Insert Post Plugin and Approval from admin
Author: The Digi Life
Version: 1.0
Author URI: http://thedigilife.com
*/
add_shortcode('insertpost','display_insert_form');
function display_insert_form($atts)
{
	if ( !empty($_POST) && !wp_verify_nonce($_POST['insert'],'insert_form') )
	{
		echo 'Sorry, Problem in submitting form';
	}
	else
	{
		// process form data
		$post_data = array(
		'post_title' => $_POST['title'],
		'post_content' => $_POST['description'],
		'post_status' => 'pending',
		'post_author' => 1,
		'post_category' => null
		);
		if($post_id = wp_insert_post($post_data)) echo "Data Succcessfully added";
	}
	?>
	<form action="" method="post" name="insert_form">
		<table>
			<tr>
				<td><label>Title</label></td>
				<td><input type="text" name="title" id="title"></td>
			</tr>
			<tr>
				<td><label>Description</label></td>
				<td><textarea rows="7" cols="10" name="description" id="description"></textarea></td>
			</tr>
			<tr>
				<td colspan="2"><input type="submit" id="button"></td>
			</tr>
			<?php wp_nonce_field('insert_form','insert'); ?>
		</table>
	</form>
	<?php
}

We can insert post in wordpress using wp_insert_post which is explained Here

In this sample I have created one sample shortcode for displaying plugin on front and in short code function I have added form to display and before that if post is submitted we will insert the post into database.

 Download | Source Code