Skip to:
Content
Pages
Categories
Search
Top
Bottom

Activity Sitewide stream filter posts by category


  • superp777
    Participant

    @superp777

    Hi,

    Anyone know a way to filter new blog posts and comments updates in the activity feed based on post category?

    Thanks a lot

    Plamen

Viewing 7 replies - 1 through 7 (of 7 total)

  • Venutius
    Moderator

    @venutius

    Hi there,

    Are you talking about a category assigned to a WordPress post? Or are you looking to assign categories to activity posts and filter on that?


    superp777
    Participant

    @superp777

    Sorry,

    Wasn’t clear enough. We have many different WordPress post categories on our blog.
    My goal is go get updates on new posts and comments from one category only.

    Thanks a lot


    Venutius
    Moderator

    @venutius

    That would be pretty difficult to do, or at least it’s not trivial. The issue is that the function used to populate the activity page does not have the ability to filter based on post settings, so you’d have to create a function to do that. Probably you’d end up overloading the activity page and displaying your own custom activity loop which took into account the post taxonomies.


    superp777
    Participant

    @superp777

    function buddydev_disable_category_post_from_activity_recording( $enabled, $blog_id, $post_id, $user_id, $comment_id ) {
    
    	$category_id = 1;
    	$taxonomy    = 'category';
    
    	if ( has_term( $category_id, $taxonomy, $post_id, $comment_id ) ) {  // I could use has_category() but has_terms can be a better example for future customization.
    		$enabled = false;
    	}
    
    	return $enabled;
    }
    
    add_filter( 'bp_activity_post_pre_publish', 'buddydev_disable_category_post_from_activity_recording', 10, 4 );

    I was able to filter new posts with the code above but not sure how to use it for comments as well

    Thanks a lot, @Venutius!


    Venutius
    Moderator

    @venutius

    That’s great! I was thinking you wanted to record the activity but just not display it and got stuck in treakle, glad you found that hook.


    superp777
    Participant

    @superp777

    Yes, but it is blocking new post updates only.

    If someone leaves a comments it shows up in the activity feed. Any way to tweak it for that?

    Thanks a lot!

    Plamen


    superp777
    Participant

    @superp777

    If anyone is looking for similar functionality the code below worked just great for me:

    function buddydev_disable_activity_blog_comment_recording_conditionally( $enabled, $blog_id, $post_id, $user_id, $comment_id ) {
    
    	// use $post_id to decide.
    	// set $enabled= false; to stop recording comment.
    	if ( ! in_category( 'category', $post_id ) ) {
    		$enabled = false;
    	}
    
    	return $enabled;
    }
    
    add_filter( 'bp_activity_post_pre_comment', 'buddydev_disable_activity_blog_comment_recording_conditionally', 20, 5 );

    Just change “category” with the name of the category you want to get updates from.

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.
Skip to toolbar