Advertisement
Guest User

Untitled

a guest
Jun 21st, 2016
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. <?php /* Template Name: Question Form */
  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. $industry = $_POST['trademan-industry'];
  18.  
  19. // Add the content of the form to $post as an array
  20. $new_post = array(
  21. 'post_title' => $title,
  22. 'post_industry' => array($industry),
  23. 'post_content' => $description,
  24. 'tags_input' => array($tags),
  25. 'post_address' => array($address),
  26. 'post_status' => 'draft', // Choose: publish, preview, future, draft, etc.
  27. 'post_type' => 'trademen' //'post',page' or use a custom post type if you want to
  28. );
  29. //save the new post
  30. $pid = wp_insert_post($new_post);
  31. wp_redirect(get_permalink($pid)); exit;
  32. //insert taxonomies
  33. }
  34. ?>
  35. <?php get_header(); ?>
  36.  
  37. <div id="wrap">
  38. <div id="header">
  39. <?php get_template_part('logo');
  40. get_template_part('nav'); ?>
  41. </div>
  42. <div id="content">
  43. <div id="main">
  44. <?php get_template_part('searches'); ?>
  45. <div class="single-post-item">
  46. <h1>Ask a Question</h1>
  47. <div class="post-meta">Fill out the fields below, all of them are required!</div>
  48. <div class="inner-content">
  49. <!-- New Post Form -->
  50. <div id="postbox">
  51. <form id="new_post" name="new_post" method="post" action="">
  52. <!-- post name -->
  53. <p><label for="title">Title</label><br />
  54. <input type="text" id="title" value="" tabindex="1" size="20" name="title" />
  55. </p>
  56.  
  57. <!-- post name -->
  58. <p><label for="title">Industry Sector</label><br />
  59. <input type="text" id="trademan-industry" value="" tabindex="2" size="20" name="trademan-industry" />
  60. </p>
  61.  
  62.  
  63. <!-- post Content -->
  64. <p><label for="description">Content</label><br />
  65. <textarea id="description" tabindex="4" name="description" cols="50" rows="6"></textarea>
  66. </p>
  67.  
  68. <!-- post tags -->
  69. <p><label for="post_tags">Tags:</label>
  70. <input type="text" value="" tabindex="5" size="16" name="post_tags" id="post_tags" /></p>
  71.  
  72.  
  73. <p align="right"><input type="submit" value="Publish" tabindex="6" id="submit" name="submit" /></p>
  74.  
  75. <input type="hidden" name="action" value="new_post" />
  76. <?php wp_nonce_field( 'new-post' ); ?>
  77. </form>
  78.  
  79. </div>
  80. </div>
  81. </div>
  82. </div>
  83. <?php get_sidebar(); ?>
  84. </div>
  85. </div>
  86. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement