Advertisement
atultiwari

AnsPress

Nov 17th, 2014
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.00 KB | None | 0 0
  1. <?php
  2. require('wp-blog-header.php');
  3.  
  4. define('ANSPRESS_VOTE_META', '_ap_vote');
  5. define('ANSPRESS_FAV_META', '_ap_favorite');
  6. define('ANSPRESS_CLOSE_META', '_ap_close');
  7. define('ANSPRESS_FLAG_META', '_ap_flag');
  8. define('ANSPRESS_VIEW_META', '_views');
  9. define('ANSPRESS_UPDATED_META', '_ap_updated');
  10. define('ANSPRESS_ANS_META', '_ap_answers');
  11. define('ANSPRESS_SELECTED_META', '_ap_selected');
  12. define('ANSPRESS_BEST_META', '_ap_best_answer');
  13. define('ANSPRESS_PARTI_META', '_ap_participants');
  14.  
  15. define('AP_FOLLOWERS_META', '_ap_followers');
  16. define('AP_FOLLOWING_META', '_ap_following');
  17.  
  18. $question_title = "This space is for Question Title...";
  19. $user_id = 1;
  20. $question_description = "This space is for actual/detailed question post";
  21. $category = array(12, 13, 15);
  22. $tags = array(21, 22, 23);
  23.  
  24. $status = 'publish';
  25.  
  26. $question_array = array(
  27.     'post_title' => $question_title,
  28.     'post_author' => $user_id,
  29.     'post_content' => wp_kses($question_description, ap_form_allowed_tags()),
  30.     'post_type' => 'question',
  31.     'post_status' => $status
  32. );
  33.  
  34. $post_id = wp_insert_post($question_array);
  35.  
  36. if ($post_id) {
  37.    
  38.     wp_set_post_terms($post_id, $category, 'question_category');
  39.     wp_set_post_terms($post_id, $tags, 'question_tags');
  40.  
  41.     update_post_meta($post_id, ANSPRESS_VOTE_META, '0');
  42.     update_post_meta($post_id, ANSPRESS_FAV_META, '0');
  43.     update_post_meta($post_id, ANSPRESS_CLOSE_META, '0');
  44.     update_post_meta($post_id, ANSPRESS_FLAG_META, '0');
  45.     update_post_meta($post_id, ANSPRESS_VIEW_META, '0');
  46.     update_post_meta($post_id, ANSPRESS_UPDATED_META, current_time('mysql'));
  47.     update_post_meta($post_id, ANSPRESS_SELECTED_META, false);
  48.    
  49.     ap_add_parti($post_id, $user_id, 'question');
  50.    
  51.     update_post_meta($post_id, ANSPRESS_ANS_META, '0');
  52.  
  53.     do_action('ap_after_inserting_question', $post_id);
  54.     ap_do_event('new_question', $post_id, $user_id);
  55.    
  56.     $question_permalink = get_permalink($post_id);
  57. }
  58.  
  59. echo "<a href='$question_permalink'>link</a>";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement