Nexus

  • Home
  • Science
  • Politics
  • Technology
  • Space
  • News
  • Health


Home Unlabelled How to add frontend post / content addition option in WordPress

How to add frontend post / content addition option in WordPress

By 0x000216
Tuesday, May 19, 2015
Read
Add Comment
Step 1. Create a new page with this page template
Step 2. Fill the form, to create a post
Step 3. Check Dashboard, post added or not.

Note: You can change post type and status from here

  1.  'post_type' => 'post',
  2.  'post_status' => 'publish'





  1. /**
  2.  * Template Name: Front End Submission
  3.  */
  4. get_header(); ?>
  5.        
  6.                 
  7.                 /*
  8.                  * If sent, analyze form data and store them in variables
  9.                  */
  10.                 if (isset($_POST['submit'])) {
  11.                         $name = htmlspecialchars($_POST['myname']);
  12.                         $email = sanitize_email($_POST['myemail']);
  13.                         $message = wp_kses_post($_POST['mymessage']);
  14.                 /*
  15.                  * Create a post for post type "post"
  16.                  */
  17.                 $contact_post = array(
  18.                         'post_title' => $name . ' | ' . $email,
  19.                         'post_content' => $message,
  20.                         'post_type' => 'post',
  21.                         'post_status' => 'publish'
  22.                 );
  23.                 if (wp_insert_post($contact_post)) echo 'Post Added for admin review.
    '
    ;
  24.                 else echo 'Try again: fill the fields';
  25.                 /*
  26.                  * Displaying the basic form
  27.                  */
  28.                 } else { ?>
  29.                        
     echo the_permalink(); ?>" method="post">
  30.                                
  31.                                
  32.                                
  33.                                
  34.                                
  35.                                
  36.                                
  37.                                
  38.                                
  39.                                
  40.                        
  41.                  } ?>
  42.        
  •  get_sidebar(); ?>
  •  get_footer(); ?>
  • How to add frontend post / content addition option in WordPress How to add frontend post / content addition option in WordPress Reviewed by 0x000216 on Tuesday, May 19, 2015 Rating: 5
    Tags :
    Share it Tweet it Share it Share it Pin it

    You Might Also Like

    Recent Posts

    Facebook

    Created By Nexus · Powered by Blogger
    © All Rights Reserved

    Terms Of Service · Privacy Policy · Disclaimer · Contact Us · About Us