Skip to:
Content
Pages
Categories
Search
Top
Bottom

Including post categories in the activity stream

  • @ewebber

    Participant

    Hi, I would like to include the blog post categories in the activity stream meta. Anyone know how I can do that?

    so instead of: ewebber wrote a new post, Scooter Router: routes from Hackney about 16 hours ago
    It would say: ewebber wrote a new post, Scooter Router: routes from Hackney in the categories scooter clapton about 16 hours ago

    I’m running WP 3.8.1 and BP 1.9.2
    My site is at http://www.yeahhackney.com

    Thanks

Viewing 7 replies - 1 through 7 (of 7 total)
  • @ewebber

    Participant

    Just adding a comment so I can sign up to replies

    @henrywright

    Moderator

    Hi @ewebber

    You can do that by filtering bp_blogs_activity_new_post_action

    @ewebber

    Participant

    Thanks for responding, any chance you know of a tutorial for this, my php knowledge is pretty lacking.

    @henrywright

    Moderator

    I’m not aware of an exact tutorial but to give you an overview of what needs to be done…

    You can use wp_get_post_categories() to get a list of categories for a particular post.

    For more information on how to use wp_get_post_categories(), see:
    https://codex.wordpress.org/Function_Reference/wp_get_post_categories

    add_filter() will let you hook your filter function to bp_blogs_activity_new_post_action

    https://codex.wordpress.org/Function_Reference/add_filter

    More info on WordPress filters:
    https://codex.wordpress.org/Plugin_API#Filters

    @ewebber

    Participant

    Awesome, thanks Henry

    @ewebber

    Participant

    I have now done this by adding:

    if( $post->post_type == 'post' ) {
    
    $activity_action  = sprintf( __( '%1$s added the post, %2$s in the categories %3$s', 'buddypress' ), bp_core_get_userlink( (int) $post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>', get_the_category_list( ', ', '', $post->ID ) );
    
    }

    Into my filter for recording posts and custom post types

    @henrywright

    Moderator

    Using get_the_category_list makes displaying the categories very simple! Nice find.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Including post categories in the activity stream’ is closed to new replies.
Skip to toolbar