Skip to content

Instantly share code, notes, and snippets.

@atultiwari
Created November 23, 2017 02:58
Show Gist options
  • Save atultiwari/f99656c899d0f1faef9125d6b0db098c to your computer and use it in GitHub Desktop.
Save atultiwari/f99656c899d0f1faef9125d6b0db098c to your computer and use it in GitHub Desktop.
Add question programmatically in Anspress
$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);
if ($question_post_id) {
wp_set_post_terms($question_post_id, $category, 'question_category');
wp_set_post_terms($question_post_id, $tags, 'question_tag');
$answer_permalink = get_permalink($answer_post_id);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment