Display Author Posts in Buddypress User Profile

Here’s a short Buddypress code snippet which will implement author made posts to their user Buddypress profiles. First it introduces a new profile tab, in this case named My Posts, followed by a simple query to get the author’s posts.

You can easily structure the posts by linking to your specific template part in get_template_part( 'member-posts' ); . For instance, linking archive.php could save time over having to create a new template part.

Finally, if the user isn’t the author of any posts, a message will be displayed in the Buddypress My Post profile tab.

Copy paste the following code to your function.php or bp-custom.php.

 

2 Comments

  1. Thank you for this code snippet. The snippet works to show the recent 5 posts on the profile. But does not include the pagination to next page that includes post 6 to 10 and so on. Can you please guide on how to add pagination to this code?

    1. Hi Nitin, there are some pretty good posts out there on doing custom wordpress loop paginations. Check out http://callmenick.com/post/custom-wordpress-loop-with-pagination or you can dig through https://codex.wordpress.org/Pagination for some examples.

      As for including more posts on the first page, you can quickly change that by adding, for instance, showposts=12 in the wp_query. So the code would look like this:

      $query = new WP_Query( ‘showposts=12&author=’ . $user_id );

      The number 12 is, of course, changeble to however many posts you want on the first page. Let me know what you come up with or if you need more help.

Leave a Reply

Your email address will not be published. Required fields are marked *