Skip to content

Instantly share code, notes, and snippets.

@boonebgorges
Created September 21, 2016 03:03
Show Gist options
  • Save boonebgorges/7f831b29f58fbb4c6488a323c2db6cc2 to your computer and use it in GitHub Desktop.
Save boonebgorges/7f831b29f58fbb4c6488a323c2db6cc2 to your computer and use it in GitHub Desktop.
populate comments and posts in bp-activity
<?php
$site_id = 7177;
switch_to_blog( $site_id );
$links = get_bookmarks( array(
'category_name' => 'Course Blogs',
) );
$urls = wp_list_pluck( $links, 'link_url' );
restore_current_blog();
global $wpdb;
$site_ids = array();
foreach ( $urls as $url ) {
$parts = parse_url( $url );
$site_ids[ $url ] = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM {$wpdb->blogs} WHERE domain = %s", $parts['host'] ) );
}
foreach ( $site_ids as $site_id ) {
switch_to_blog( $site_id );
add_post_type_support( 'post', 'buddypress-activity' );
$q = new WP_Query( array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
) );
foreach ( $q->posts as $the_post ) {
if ( 1 == $the_post->ID ) {
continue;
}
bp_activity_post_type_publish( $the_post->ID, $the_post );
$post_comments = get_comments( array(
'post_id' => $the_post->ID,
'status' => 'approve',
) );
foreach ( $post_comments as $the_comment ) {
bp_activity_post_type_comment( $the_comment->comment_ID, true );
}
}
restore_current_blog();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment