bbPress

Simple, Fast, Elegant

bbPress support forums » Requests and Feedback

Favourites

(8 posts)
  1. What are the possibilities about the way favourites are being stored changing anytime soon? The current method makes it easy to pull the favourites for a given user, but going the other way ("How many people have favourited this topic?") less than easy.

    Posted 1 year ago #
  2. I don't think the way the default system calls the favorites changing will happen anytime soon, but a plugin would definetely work to pull that information from the database in the way you want.....just need a plugin author to take this on!

    Trent

    Posted 1 year ago #
  3. Here's a function I whipped up to grab the number of users who call any particular topic a favorite.

    If you don't send it a topic id, it return the currently displayed topic's favorite count

    function get_topic_favorites_count( $topic_id=0) {
    	global $bbdb, $topic;
    	if (!$topic_id) $topic_id = (int) $topic->topic_id;
    	return $bbdb->get_var("SELECT COUNT(*) FROM ".$bbdb->usermeta." WHERE meta_key='bb_favorites' AND meta_value REGEXP '[[:<:]]".$topic_id."[[:>:]]'");
    }

    use it this way:
    <? echo get_topic_favorites_count(); ?>
    within your topic.php template

    Posted 1 year ago #
  4. I have a sneaking suspicion that you could help solve some serious bbPress issues quickly! Thought about helping DEV?

    Trent

    Posted 1 year ago #
  5. Heh, thanks for the compliment but I am completely self-trained and rather unprofessional in my code (translation: I'd make a mess)

    I just seem to have a knack at code, I learn very quickly from examples and can figure out how to apply them. Also, exhaustive hours at hacking pre-2.0 wordpress taught me a lot.

    ps. what "serious" issues - I might have a go... maybe...

    Posted 1 year ago #
  6. It appears that functionget_topic_favorites_count is not working in 0.9 - anyone know how to make it working? And generally - this function won't kill my DB, will it? lol

    Posted 3 months ago #
  7. It's just a query, doesn't write anything so can't hurt your db. Only bad thing it could do if it you used it on a frequently accessed page, might slow down your site a little bit.

    I'll double check why it's not working in 0.9

    update: oh they changed the name of the field from "favorites" to "bb_favorites" so it's like this now:

    function get_topic_favorites_count( $topic_id=0) {
    	global $bbdb, $topic;
    	if (!$topic_id) $topic_id = (int) $topic->topic_id;
    	return $bbdb->get_var("SELECT COUNT(*) FROM ".$bbdb->usermeta." WHERE meta_key='bb_favorites' AND meta_value REGEXP '[[:<:]]".$topic_id."[[:>:]]'");
    }
    Posted 3 months ago #
  8. Hmm... bbSuperCache plugin could be useful, muhaha! Thanks ;)

    Posted 3 months ago #

RSS feed for this topic

Reply

You must log in to post.

Code is Poetry.