Skip to:

Exclude single user’s posts from main activity feed only

  • graeme_bryson


    I’m looking to exclude a single user ID from the main activity feed only. Directly above the main feed, I’m using a shortcode to pull in the latest post from this same single user, thus creating a ‘sticky’ post as this account only posts announcements. However, the code below seems to hide the user’s content across the entire site, so it doesn’t appear in either the shortcode-generate feed or the main feed.

    Essentially, is there a way I can specifically target the main buddypress activity feed only with this exclusion? Thanks in advance for any help you can provide.

    // hide admin's activities from all activity feeds
    function bpfr_hide_admin_activity( $a, $activities ) {
    	// ... but allow admin to see his activities!
    	if ( is_site_admin() )
    	return $activities;
    	foreach ( $activities->activities as $key => $activity ) {
    		// ID's to exclude, separated by commas. ID 1 is always the superadmin
    		if ( $activity->user_id == 784  ) {			
    			unset( $activities->activities[$key] );
    			$activities->activity_count = $activities->activity_count-1;
    			$activities->total_activity_count = $activities->total_activity_count-1;
    			$activities->pag_num = $activities->pag_num -1;
    	// Renumber the array keys to account for missing items
    	$activities_new = array_values( $activities->activities );
    	$activities->activities = $activities_new;
    	return $activities;
    add_action( 'bp_has_activities', 'bpfr_hide_admin_activity', 10, 2 );
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.
Skip to toolbar