Created
May 26, 2016 05:56
-
-
Save atultiwari/28e7cb9275d6306bf686e4fd1d0a9919 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function AddQuestionToAnsPress($question_title, $question_content, $answer_content, $subject_id, $exam_id) { | |
$path = $_SERVER['DOCUMENT_ROOT']; | |
$path .= "/wp-blog-header.php"; | |
require($path); | |
$question_title = strip_tags($question_title); | |
$category_id = $subject_id; | |
$category = array($category_id); | |
$tag_subject_id = $subject_id; | |
$tags = array(25, $tag_subject_id); | |
wp_set_current_user(26); | |
$user_id_for_question = 26; | |
$question_array = array( | |
'post_title' => $question_title, | |
'post_author' => $user_id_for_question, | |
'post_content' => $question_content, | |
'post_type' => 'question', | |
'post_status' => 'publish', | |
'comment_status' => 'open' | |
); | |
$question_post_id = wp_insert_post($question_array); | |
$question_permalink = get_permalink($question_post_id); | |
wp_set_post_terms($question_post_id, $category, 'question_category'); | |
wp_set_post_terms($question_post_id, $tags, 'question_tag'); | |
update_post_meta($question_post_id, '_at_exam_id', $exam_id); | |
$anspress_link = $question_permalink; | |
return array('anspress_link' => $anspress_link, 'question_post_id' => $question_post_id); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment