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.
bbPress support forums » Requests and Feedback
Favourites
(8 posts)-
Posted 1 year ago #
-
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 # -
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 templatePosted 1 year ago # -
I have a sneaking suspicion that you could help solve some serious bbPress issues quickly! Thought about helping DEV?
Trent
Posted 1 year ago # -
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 # -
It appears that function
get_topic_favorites_countis not working in 0.9 - anyone know how to make it working? And generally - this function won't kill my DB, will it? lolPosted 3 months ago # -
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 # -
Hmm... bbSuperCache plugin could be useful, muhaha! Thanks ;)
Posted 3 months ago #
Reply
You must log in to post.