Skip to:
Content
Pages
Categories
Search
Top
Bottom

Favourites

  • 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.

Viewing 7 replies - 1 through 7 (of 7 total)
  • 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


    _ck_
    Participant

    @_ck_

    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

    I have a sneaking suspicion that you could help solve some serious bbPress issues quickly! Thought about helping DEV?

    Trent


    _ck_
    Participant

    @_ck_

    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…

    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


    _ck_
    Participant

    @_ck_

    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.":>:'");
    }

    Hmm… bbSuperCache plugin could be useful, muhaha! Thanks ;)

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.
Skip to toolbar