Adding custom post type to buddypress activity, the right approach

So, here I was working on a buddypress based site trying to figure out a way to add the custom post type to my activity. After a lot of research and putting a whole of mind I finally figured out the most effective (at least for me) way to add a custom post type to buddypress activity.

So how to do it:

First step is to make a child theme, trust me on this one, a child theme is the best practice you can adopt while working on an project, it allows you to make necessary customizations to your site and never gets disturbed when you update the parent theme, unless of-course you are making a parent theme ;). To know how to create a child theme refer the codex: https://codex.wordpress.org/Child_Themes

Second step is to add a line to functions.php (which you have made while creating the child theme). So add this to functions.php:

Note: Replace your_custom_post_type with your custom post type slug.
So, by adding the afore-stated lines in the functions.php you are actually preparing the buddypress activity to record the posts you publish using your custom post type. So next time when you post the custom post type it will be recorded by the buddypress as one of your activity.

Next step is to display the contents of the custom post type we made. To do so, we need to make changes to the loop of activity in buddypress. It is considerable that the loop exists in one of the template file of the buddypress(Plugin) i.e. entry.php, which we can not change because as soon as it will be updated, the changes will override with original file. So the trick is to create a separate directory in our child theme. To do so create a folder named “buddypress” in you child theme’s home directory. Create folder with name of “activity” inside buddypress folder. Now create “entry.php” in the activity folder and put following code in it:

This will override the original entry.php code. By adding this code, you will be able to display the featured image and the content of the custom post. To add other meta data or content from the custom post you can use the usual wordpress functions by using “$blogpost_id” as post id. For Example the code below can be used to display the post title:

One Reply to “Adding custom post type to buddypress activity, the right approach”

OMG, thank you so much! I am like ready to die right now because it worked for my plugin. This is my first time following someone’s instructions and actually understanding it to get it to work. Thank you!