Last active
August 29, 2015 14:27
-
-
Save atultiwari/cd9b5d00e54c238a02d1 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 | |
$db = @mysql_connect('localhost', 'root', 'password') or die(mysql_error()); | |
mysql_select_db('test', $db) or die(mysql_error()); | |
$qry_qbank = mysql_query("SELECT * FROM at_qa_dump limit 100") or die(mysql_error()); | |
//require('wp-blog-header.php'); | |
while ($row = mysql_fetch_array($qry_qbank)) { | |
$qno = $row['ID']; | |
$question_title = $row['Question_Title']; | |
$question_content = $row['Question_Content']; | |
$answer_content = $row['Answer_Content']; | |
$category = array($row['Category_Id']); | |
$tags = array($row['Tag_Id']); | |
wp_set_current_user($row['Question_User_Id']); | |
$user_id_for_question = $row['Question_User_Id']; | |
$user_id_for_answer = $row['Answer_User_Id']; | |
$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'); | |
wp_set_current_user($row['Answer_User_Id']); | |
$ans_array = array( | |
'post_author' => $user_id_for_answer, | |
'post_content' => $answer_content, | |
'post_type' => 'answer', | |
'post_status' => 'publish', | |
'post_parent' => $question_post_id, | |
'comment_status' => 'open', | |
); | |
$answer_post_id = wp_insert_post($ans_array); | |
$question_permalink = get_permalink($question_post_id); | |
$answer_permalink = get_permalink($answer_post_id); | |
} | |
//$update_qry_qbank = mysql_query("Update at_qa_dump set Anspress_Question_Id='" . $question_permalink . "' where ID='" . $qno . "'") or die(mysql_error()); | |
$qno.= " / " . $question_post_id; | |
echo "<a href='$question_permalink'>question - {$qno} - link</a>"; | |
echo "<br/>"; | |
echo "<a href='$answer_permalink'>answer - {$qno} - link</a>"; | |
echo "<br/>"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment