I'd like to create a list of recent comments, specific to each user on my network (Buddypress).

My best idea so far is pretty lame: DB Query on all user's blogs, compare dates, select top 10 by date. To me, it sounds a too heavy load for the the server.

Any alternative and better ideas? :)


  • Are these comments going to appear on A WordPress site or on a BuddyPress site? – kevtrout Nov 12 '10 at 12:57
  • Does the BuddyPress still have the wp_bp_user_blogs_comments table? – prettyboymp Nov 12 '10 at 15:22
  • RE:wp_bp_user_blogs_comments -- Nope. Doesn't seem to have that table. Any configuration I should know about? Sounds useful. – konzepz Nov 12 '10 at 17:52
  • Its not a config change. The sites we're running BP on are still running from the beta, so its either left over from that or a mod we made. I just saw it in the db and thought it may be a quick solution. – prettyboymp Nov 12 '10 at 21:46

There's a different posts and comments table per site, so not really.

That said, you can and should keep track of blog ids they've commented on in a user meta to speed things up in the first round, and cache the formatted result in a separate usermeta to speed things up in subsequent rounds. These are easy enough to be tracked and invalidate on save/delete post/comment.

  • Very interesting. Thanks. How do I do that? Create new tables and manage them? Use existing WP/BP tables? (I'm not very experienced with caching methods). – konzepz Nov 12 '10 at 18:00
  • Just use the user meta API... – Denis de Bernardy Nov 12 '10 at 21:34
  • The chief difficulty with caching is invalidation. The part that goes if in cache then serve it and bail, else store the output before returning or outputting it, is trivial. The part that's not is what happens when the post/comment gets updated/deleted or when it's URL changes. All of these can and should be invalidated using the available WP filters. – Denis de Bernardy Nov 12 '10 at 21:37

The activity feed shows comments from any blogs from all persons registered in the buddypress site (pulldown menu show recent comments) so why not duplicate it, sort it and dump it in a widget on the screen?

  • Sounds like a good idea. Do you have any idea what should be modified so it'll show just comments on MY blogs? (Say I own A and B blog -- exclude comments from C, D ... n) – konzepz Nov 12 '10 at 17:53
  • I'm more of a lazy hobby developer so I just hardcode it in the php... purists will make a widget where you select the existing users from a pull down menu... – edelwater Nov 12 '10 at 19:28

If you're using the blog tracking feature of BuddyPress, rather than querying WordPress' comments tables, I suggest you query the activity stream for 'new_blog_comment' updates only. The activity stream already records and aggregates this information into one database table.
Something like:

if ( bp_has_activities( 'user_id=1&object=blog&action=new_blog_comment' ) )

See also http://codex.buddypress.org/developer-docs/custom-buddypress-loops/the-activity-stream-loop/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.