i create a front end post from , i just create a short code , and inside shortcode you will i put form and form process . please see below
now i will explain
add_shortcode( 'front_end_post_form', 'front_end_post_form' );
function front_end_post_form( $atts ) {
you know this WordPress shortcode and this shortcode function .
this jquery function is for hide Sucess Message .
if(isset($_POST['submitted']) && isset($_POST['post_nonce_field']) && wp_verify_nonce($_POST['post_nonce_field'], 'post_nonce')) {
this line checking is Form is submitted or not ? if is submitted this function will run below command or it will go in else .
if (trim($_POST['postTitle']) === '' || $_POST['postContent'] === '' ) {
if(trim($_POST['postTitle']) === '') {
$postTitleError = 'Please enter a title.';
}
if(trim($_POST['postContent']) === '') {
$postcontentError = 'Please enter a title.';
}
this is just checking validation , is post title is empty or not ,
$post_information = array(
'post_title' => esc_attr(strip_tags($_POST['postTitle'])),
'post_content' => esc_attr(strip_tags($_POST['postContent'])),
'post_status' => 'pending',
'post_type' => 'post'
);
$post_id = wp_insert_post($post_information);
after submission of post this is will hide form and show sucess masagee .
full code is here
if post title and post content is not empty , then will run this code , for details you can see this .
WordPress.org
No comments:
Post a Comment