Advertisement
Guest User

Untitled

a guest
Mar 8th, 2011
3,615
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.25 KB | None | 0 0
  1. <?php /* Template Name: Question Form */ get_header();
  2.  
  3. if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) &&  $_POST['action'] == "new_post") {
  4.  
  5. // Do some minor form validation to make sure there is content
  6. if (isset ($_POST['title'])) {
  7.     $title =  $_POST['title'];
  8. } else {
  9.     echo 'Please enter a  title';
  10. }
  11. if (isset ($_POST['description'])) {
  12.     $description = $_POST['description'];
  13. } else {
  14.     echo 'Please enter the content';
  15. }
  16. $tags = $_POST['post_tags'];
  17.  
  18. // Add the content of the form to $post as an array
  19. $new_post = array(
  20.     'post_title'    => $title,
  21.     'post_content'  => $description,
  22.     'post_category' => array($_POST['cat']),  // Usable for custom taxonomies too
  23.     'tags_input'    => array($tags),
  24.     'post_status'   => 'publish',           // Choose: publish, preview, future, draft, etc.
  25.     'post_type' => 'post'  //'post',page' or use a custom post type if you want to
  26. );
  27. //save the new post
  28. $pid = wp_insert_post($new_post);
  29. wp_redirect(get_permalink($pid)); exit;
  30. //insert taxonomies
  31. } ?>
  32.  
  33. <div id="wrap">
  34.     <div id="header">
  35.         <?php get_template_part('logo');
  36.         get_template_part('nav'); ?>
  37.     </div>
  38.     <div id="content">
  39.         <div id="main">
  40.             <?php get_template_part('searches'); ?>
  41.             <div class="single-post-item">
  42.                 <h1>Ask a Question</h1>
  43.                 <div class="post-meta">Fill out the fields below, all of them are required!</div>
  44.                 <div class="inner-content">
  45.                     <!-- New Post Form -->
  46.                     <div id="postbox">
  47.                         <form id="new_post" name="new_post" method="post" action="">
  48.                             <!-- post name -->
  49.                             <p><label for="title">Title</label><br />
  50.                             <input type="text" id="title" value="" tabindex="1" size="20" name="title" />
  51.                             </p>
  52.                        
  53.                             <!-- post Category -->
  54.                             <p><label for="Category">Category:</label><br />
  55.                             <p><?php wp_dropdown_categories( 'tab_index=3&taxonomy=category' ); ?></p>
  56.                            
  57.                            
  58.                             <!-- post Content -->
  59.                             <p><label for="description">Content</label><br />
  60.                             <textarea id="description" tabindex="4" name="description" cols="50" rows="6"></textarea>
  61.                             </p>
  62.                            
  63.                             <!-- post tags -->
  64.                             <p><label for="post_tags">Tags:</label>
  65.                             <input type="text" value="" tabindex="5" size="16" name="post_tags" id="post_tags" /></p>
  66.                             <p align="right"><input type="submit" value="Publish" tabindex="6" id="submit" name="submit" /></p>
  67.                            
  68.                             <input type="hidden" name="action" value="new_post" />
  69.                             <?php wp_nonce_field( 'new-post' ); ?>
  70.                         </form>
  71.                        
  72.                     </div>
  73.                 </div>
  74.             </div>
  75.         </div>
  76.         <?php get_sidebar(); ?>
  77.     </div>
  78. </div>
  79. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement