Skip to content

Instantly share code, notes, and snippets.

@kprimdal-dk
Created February 23, 2013 10:36
Show Gist options
  • Save kprimdal-dk/5019250 to your computer and use it in GitHub Desktop.
Save kprimdal-dk/5019250 to your computer and use it in GitHub Desktop.
Convert Post, Commets and Categories to bbPress
<?php
require_once('wp-blog-header.php');
set_time_limit(0);
$categories = get_terms('category');
foreach ($categories as $category) {
$default_forum = array(
'post_title' => $category->name,
);
$forum = bbp_insert_forum( $default_forum );
$args = array(
'post_type' => 'post',
'cat' => $category->term_id,
'posts_per_page' => '-1'
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
$default_topic = array(
'post_parent' => $forum,
'post_author' => $post->post_author,
'post_date' => $post->post_date,
'post_title' => $post->post_title,
'post_content' => $post->post_content
);
$default_meta = array(
'forum_id' => $forum
);
$topic = bbp_insert_topic( $default_topic, $default_meta );
$comments = get_comments( array( 'post_id' => $post->ID ) );
foreach ($comments as $comment) {
$default_reply = array(
'post_parent' => $topic, // topic ID
'post_author' => $comment->user_id,
'post_content' => $comment->comment_content,
'post_date' => $comment->comment_date,
);
$default_meta = array(
'author_ip' => $comment->comment_author_IP,
'forum_id' => $forum,
'topic_id' => $topic,
);
bbp_insert_reply( $default_reply, $default_meta );
}
endwhile;
endif;
// wp_reset_postdata();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment