Advertisement
Panag

wp_redirect

Dec 22nd, 2012
859
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.24 KB | None | 0 0
  1. <?php /* Template Name: Test Form */ get_header();
  2.  
  3. if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) &&  $_POST['action'] == "new_post") {
  4.  
  5. if (isset ($_POST['title'])) {
  6.     $title =  $_POST['title'];
  7. } else {
  8.     echo 'Please enter a  title';
  9. }
  10. if (isset ($_POST['description'])) {
  11.     $description = $_POST['description'];
  12. } else {
  13.     echo 'Please enter the content';
  14. }
  15. if (isset ($_POST['domain'])) {
  16.     $domain = esc_attr($_POST['domain']);
  17. } else {
  18.     echo 'Please enter the domain';
  19. }
  20. if (isset ($_POST['keywords'])) {
  21.     $keywords = sanitize_text_field ($_POST['keywords']);
  22. } else {
  23.     echo 'Please enter the keywords';
  24. }
  25. $tags = $_POST['post_tags'];
  26.  
  27. $new_post = array(
  28.     'post_title'    => $title,
  29.     'post_content'  => $description,
  30.     'post_category' => array($_POST['cat']),  // Usable for custom taxonomies too
  31.     'tags_input'    => array($tags),
  32.     'post_status'   => 'publish',           // Choose: publish, preview, future, draft, etc.
  33.     'post_type' => 'website'  //'post',page' or use a custom post type if you want to
  34. );
  35.  
  36. $pid = wp_insert_post($new_post);
  37. update_post_meta($pid,'domain',$domain);
  38. update_post_meta($pid,'keywords',$keywords);
  39.  
  40. wp_redirect( get_permalink($pid) );
  41. exit();
  42. //insert taxonomies
  43. } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement