Replies
- Plamen Peev on April 16, 2019 at 11:31 am in reply to: [Resolved] Activity Sitewide stream filter posts by category #22321
Thanks, Brajesh,
Appreciate your assistance.
Actually I had a code in place that seemed to work but suddenly stopped.Here it is:
if ( ! function_exists( 'ucc_wp_insert_post_bp_blogs_record_post' ) ) { function ucc_wp_insert_post_bp_blogs_record_post() { remove_action( 'save_post', 'bp_blogs_record_post', 10, 2 ); add_action( 'wp_insert_post', 'bp_blogs_record_post', 10, 2 ); } } add_action( 'init', 'ucc_wp_insert_post_bp_blogs_record_post' ); // Set hide_sitewide to true if the activity should be excluded. if ( ! function_exists( 'ucc_bp_activity_before_save' ) ) { function ucc_bp_activity_before_save( &$args ) { global $wpdb; if ('new_blog_post' == $args->type ) { $post_id = $args->secondary_item_id; $comment_ids = array(); $comments = get_comments( "post_id=$post_id" ); foreach ( $comments as $comment ) { $comment_ids[] = $comment->comment_ID; } if ( in_category( 'community', $post_id ) ) { $args->hide_sitewide = false; if ( ! empty( $comment_ids ) ) { $result = $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->prefix" . "bp_activity SET hide_sitewide = 1 WHERE secondary_item_id IN (" . implode( ',', $comment_ids ) . ")" ) ); } } else { $args->hide_sitewide = true; if ( ! empty( $comment_ids ) ) { $result = $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->prefix" . "bp_activity SET hide_sitewide = 0 WHERE secondary_item_id IN (" . implode( ',', $comment_ids ) . ")" ) ); } } } if ( 'new_blog_comment' == $args->type ) { $comment_id = $args->secondary_item_id; $comment = get_comment( $comment_id ); if ( in_category( 'community', $comment->comment_post_ID ) ) { $args->hide_sitewide = false; } else { $args->hide_sitewide = true; } } } } add_action( 'bp_activity_before_save', 'ucc_bp_activity_before_save', 10, 1 ); add_filter( 'bp_after_has_activities_parse_args', 'ray_bp_display_comments_stream' );
Thanks a lot again
Regards,
Plamen