Skip to:

New Activity custom type groups

  • palessio23


    Hello everybody
    I’m trying to put the new activity (custom type) into a specific group.

    I am using bp_activity_set_post_type_tracking_args, the problem is in the item_id because set default 1 and not get the custom id group

    How can I change the item id with bp_activity_set_post_type_tracking_args?


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

  • etatus


    I’m also interested in solving this problem (I think the number 1 is actually the user id). The only way I could find is to use bp_before_activity_add_parse_args filter:

    function me_activity_parse_filter( $cpt ) {
        if ( $cpt['type'] == 'your_custom_type' ) {
            $cpt['item_id'] = bp_get_current_group_id();
        return $cpt;
    add_filter('bp_before_activity_add_parse_args', 'me_activity_parse_filter');

    However, if the cpt post is updated a new activity is created instead updating the original one…

    Note that in bp_activity_set_post_type_tracking_args I have
    'component_id' => 'groups',

    Maybe @imath can help us to solve this issue.



    Here is another approach. I dont like it at all because you cannot check a custom post type (you dont have the activity object). But it works.

    function me_filter_bp_activity_item_id_before_save( $item_id ) { 
        if ( !empty(bp_get_current_group_id()) ) $item_id = bp_get_current_group_id();
        return $item_id ; 
    add_filter( 'bp_activity_item_id_before_save', 'me_filter_bp_activity_item_id_before_save', 10, 1 );

    BTW: The value 1 seems to be the default blog ID.

    In this thread @imath explains that:

    Custom Post Type Support for Activity



    I found a workaround to avoid the creation of duplicate activities for the same cpt post on updating.

    function me_activity_parse_args_filter( $args = array() ) {     
        if ( !empty( $args['type'] ) && $args['type'] == 'new_your-cpt' ) {
                    $activities = bp_activity_get(array(
                            'max' => 1,
                            'filter' => array(
                            'action' => 'new_your-cpt',
                            'secondary_id' =>  $args['secondary_item_id'],
                    ) );
                    if (count($activities['activities'])==0) { // The cpt post doesn't have activity yet, so we set the group information
                            $args['component'] = 'groups'; // You could set this as 'component_id' in bp_activity_set_post_type_tracking_args
                            if ( !empty(bp_get_current_group_id()) ) $args['item_id'] = bp_get_current_group_id();
                            if (empty($args['content'])) $args['content'] = ' ';  // To make sure content filter applies afterwards 
                    } else { // Activity already exists
                            $args['type'] = false; // Delete duplicate activity
        return $args;
    add_filter('bp_after_activity_add_parse_args', 'me_activity_parse_args_filter',10,1);
Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Skip to toolbar