Sync Local and Remote AnsPress WP

7.34K viewsWordPress
0

Hi Rahul,

I was thinking if there is a way to sync both local and remote wordpress.

As I had earlier mailed you, I am looping through external database (which contains multiple choice questions with answers), to create AnsPress Questions (custom wordpress post). So it would be easier for me to create them on localhost and then somehow send these Questions on live site.

(sorry for the off-topic question)

Regards,
Atul

lol… I originally posted this question as a private, but after editing a typo, this question automatically became public. is it an issue on editing a private question or something I missed, @Rahul ?

Can you perhaps share your code on importing? I’m looking for a script I can easily modify to get my question2answer website into Anspress for WordPress

@acidrazor please see the piece of code on pastebin -http://pastebin.com/yeSdxtaK
Although as Rahul has mentioned in his reply that he will be working on migrate script soon. That’s a good news.

@atul after you posted comment avatar got fixed 😐 really weird issue

@rahul, No. it was not corrected after posting comment. Rather it was corrected after I edited the answer. i guess well someday you’ll find
1. why this happened,
2. my private question became public after editing (some more small issues i will write somewhere else :P)

need to investigate 🙂 anyway thanks fro reporting the issue

1

Well, this is NOT the answer to my original question.
@AcidRaZor, this is the piece of code I am using (and it’s NOT complete). It’s similar to what wordpress help shows on how to make wp-post in PHP.

After posting here, My code was automatically modified for unknown reasons. So I have pasted it on pastebin. It’s link is – http://pastebin.com/yeSdxtaK. Please check it there.

<?php
require('wp-blog-header.php');

define('ANSPRESS_VOTE_META', '_ap_vote');
define('ANSPRESS_FAV_META', '_ap_favorite');
define('ANSPRESS_CLOSE_META', '_ap_close');
define('ANSPRESS_FLAG_META', '_ap_flag');
define('ANSPRESS_VIEW_META', '_views');
define('ANSPRESS_UPDATED_META', '_ap_updated');
define('ANSPRESS_ANS_META', '_ap_answers');
define('ANSPRESS_SELECTED_META', '_ap_selected');
define('ANSPRESS_BEST_META', '_ap_best_answer');
define('ANSPRESS_PARTI_META', '_ap_participants');

define('AP_FOLLOWERS_META', '_ap_followers');
define('AP_FOLLOWING_META', '_ap_following');

$question_title = "This space is for Question Title...";
$user_id = 1;
$question_description = "This space is for actual/detailed question post";
$category = array(12, 13, 15);
$tags = array(21, 22, 23);

$status = 'publish';

$question_array = array(
    'post_title' => $question_title,
    'post_author' => $user_id,
    'post_content' => wp_kses($question_description, ap_form_allowed_tags()),
    'post_type' => 'question',
    'post_status' => $status
);

$post_id = wp_insert_post($question_array);

if ($post_id) {
    
    wp_set_post_terms($post_id, $category, 'question_category');
    wp_set_post_terms($post_id, $tags, 'question_tags');

    update_post_meta($post_id, ANSPRESS_VOTE_META, '0');
    update_post_meta($post_id, ANSPRESS_FAV_META, '0');
    update_post_meta($post_id, ANSPRESS_CLOSE_META, '0');
    update_post_meta($post_id, ANSPRESS_FLAG_META, '0');
    update_post_meta($post_id, ANSPRESS_VIEW_META, '0');
    update_post_meta($post_id, ANSPRESS_UPDATED_META, current_time('mysql'));
    update_post_meta($post_id, ANSPRESS_SELECTED_META, false);
    
    ap_add_parti($post_id, $user_id, 'question');
    
    update_post_meta($post_id, ANSPRESS_ANS_META, '0');

    do_action('ap_after_inserting_question', $post_id);
    ap_do_event('new_question', $post_id, $user_id);
    
    $question_permalink = get_permalink($post_id);
}

echo "<a href='$question_permalink'>link</a>";

p.s. –
1. it will only create question. I had not created for posting answers. but I think $answer_array can be created in similar manner and use that array into wp_insert_post inside if ($post_id) block
2. I am NOT a programmer. so, it may be a worst piece of code, one can see in his life-time. but if there is any other way, please share it.

Regards,
Dr. Atul Tiwari

as a non programmer you did a good try 🙂 I will make a migration within 1-2 days.

did you finish the script? I want to migrate Q2A please

@acidRaZor, check my newly posted answer

You are viewing 1 out of 3 answers, click here to view all answers.