BuddyDev

Search

[Resolved] Hide a specific post category in the activities

  • Participant
    Level: Initiated
    Posts: 11
    velli on #16469

    Hi
    I want some blog-posts i wrote to be not shown in my BP activities. i made a special post category for the posts to hide – how can i hide these posts in my activities?

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #16487

    Hi Velli,
    Please share the post type(is it post or a custom post type?) and category(term) id.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 11
    velli on #16489

    Hi Brajesh
    category tagID is 165

    Thanks
    Velli

    • This reply was modified 6 years, 4 months ago by velli.
  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #16491

    Please put the following code to your bp-custom.php

    
    
    /**
     * Disable recording posting from a specific category to BuddyPress activity 
     *
     * @param bool $enabled allow posting?
     * @param int  $blog_id blog id.
     * @param int  $post_id post id.
     * @param int  $user_id user id.
     *
     * @return bool
     */
    function buddydev_disable_category_post_from_activity_recording( $enabled, $blog_id, $post_id, $user_id ) {
    
    	$category_id = 165;
    	$taxonomy    = 'category';
    
    	if ( has_term( $category_id, $taxonomy, $post_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 );
    
    

    It will disallow any future recording of posts from that category. It won’t change the activity for already recorded posts though.

    Please test and let me know if it works for you or not?

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 11
    velli on #16506

    Works great!

    Thanks a lot!

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #16515

    You are welcome 🙂

The topic ‘ [Resolved] Hide a specific post category in the activities’ is closed to new replies.

This topic is: resolved