The duplicate posts show up because a different user edited the post, I’m not sure what this is used for, maybe to show posts you contributed to or something..
Anyway, to remove the duplicate posts all you need to do is add one word to the SELECT statement. Just add DISTINCT between “SELECT” and “p.post.id” so it looks like this: SELECT DISTINCT p.post_id, p.blog_id FROM…
That will have the query return only one result for the post even though there are two rows in the table.
The problem with the post showing up even if it is NOT published is because the post was previously save as “published” and has been changed to “unpublished”. The code currently returns if the status is unpublished so the existing entry never gets removed. To fix this you’ll need to edit a few lines in bp-blogs.php.
Around line 268
Change this:
if ( !$post || $post->post_type != 'post' || $post->post_status != 'publish' || $post->post_password != ''")
return false;
To this:
if ( !$post || $post->post_type != 'post')
return false;
This change is need to keep us in the process so we can update an existing entry if it’s status has changed.
Around line 384
Change this:
/* Don't record this if it's not a post, not published, or password protected */
if ( $post->post_type != 'post' || $post->post_status != 'publish' || $post->post_password != '' )
return false;
/**
* Check how many recorded posts there are for the user. If we are
* at the max, then delete the oldest recorded post first.
*/
if ( BP_Blogs_Post::get_total_recorded_for_user() >= TOTAL_RECORDED_POSTS )
BP_Blogs_Post::delete_oldest();
if ( !BP_Blogs_Post::is_recorded( $post_id, $blog_id ) ) {
if ( $post->post_status == 'publish' ) {
$recorded_post = new BP_Blogs_Post;
To this:
/* Don't record this if it's not a post */
if ( $post->post_type != 'post' )
return false;
if ( !BP_Blogs_Post::is_recorded( $post_id, $blog_id ) ) {
if ( $post->post_status == 'publish' ) {
/* gwrey
Moved the test for max total records inside this
block so we will only delete a record IF we are going to add a new one
*/
/**
* Check how many recorded posts there are for the user. If we are
* at the max, then delete the oldest recorded post first.
*/
if ( BP_Blogs_Post::get_total_recorded_for_user() >= TOTAL_RECORDED_POSTS )
BP_Blogs_Post::delete_oldest();
$recorded_post = new BP_Blogs_Post;
$recorded_post->user_id = $user_id;
Also needed so we keep going and update any existing entries
Around line 419
Change this:
if ( $post->post_status != 'publish' )
BP_Blogs_Post::delete( $post_id, $blog_id );
To this:
if ( $post->post_status != 'publish' || $post->post_password != '')
BP_Blogs_Post::delete( $post_id, $blog_id );
This will delete a post from the BP posts log if it is no longer published or if a password has been added.
Around line 423
Change this:
add_action( 'publish_post', 'bp_blogs_record_post' );
To this:
add_action( 'save_post', 'bp_blogs_record_post' );
This will update the post data any time it is saved, not just when published.