Forum Replies Created
-
In reply to: Link to user profile page for menu
Hi @markusb,
If I understand your issue well, I think this other topic could help you.In reply to: Specify Menue – Add โedit profileโHi!
To anyone in need of a login menu item with both user avatar and Link to the Bbpress dashboard in 2022, here’s my version of @robkk ‘s code :
add_filter('wp_nav_menu_items','rk_bbp_menu_profile_link', 10, 2); function rk_bbp_menu_profile_link( $items, $args ) { if( is_user_logged_in() && $args->theme_location == 'menu-1') { $current_user = wp_get_current_user(); $user = $current_user->user_login ; $avatar = get_avatar( $current_user->ID, 64 ); $items .= '<li class="NavBarLogin"><a href="/forums/users/' . $user . '/edit">' . $avatar . 'Mon compte</a></li>'; } return $items; }
In reply to: Get Number of Favorites & Subscription to a topicA little update on this too. ๐
The $count of favoriters is updated correctly on topic’s single page.
But when the $count is called elsewhere, WordPress seems to take the first_bbp_favorite
encounter.Looking at posts’ metavalues, it seems that every ‘favorite’ mention becomes an extra
_bbp_favorite
My code doesn’t say anything about taking the highest number – maybe this would be the solution?
$subscriptions = get_post_meta(get_the_ID(), '_bbp_favorite', true) ; $count = count($subscriptions) ; $output .= '<li><a href="' . get_permalink() . '">' . get_post_meta(get_the_ID(), 'an_extra_field', true) . '</a><br> <span> Votes :' . get_post_meta(get_the_ID(), '_bbp_favorite', true) . '</span></li>'; } $output .= '</ul>'; wp_reset_query(); } return $output; }
In reply to: Register custom view with extra_fieldsThank you @robin-w !
My first idea was todisplay:none
the_title but I’m definitely going to keep it.I found the solution by installing a plugin called Hookr. It gave me some informations I needed after hours reading Bbpress’ files.
The ouput is a bit strange though…
As if the voice-count moved somewhere. The author is also displayed twice – I don’t remember it was like that before. Changing the shortcode used doesn’t improve this.
I’m going to figure out what happened here and keep this thread updated if it’s usefull for someone. ๐
In reply to: Register custom view with extra_fieldsTo anyone who would come accross the same project, I added an action to the
bbp_theme_before_topic_title
hook.For now, it does not displays as I would like but some CSS will do the trick.
add_action('bbp_theme_before_topic_title', 'show_true_title'); function show_true_title() { $topic_id = bbp_get_topic_id(); $true_title = '<li><a href="' . get_permalink() . '">' . get_post_meta( $topic_id, 'bbp_extra_field1', true); '</a>'; echo $true_title ;
In reply to: Get Number of Favorites & Subscription to a topicThank you so much @robin-w – changed the subscription to fav with
bbp_get_topic_favoriters
๐add_action('bbp_template_before_single_topic', 'show_bbp_sub'); function show_bbp_sub() { $subscriptions = bbp_get_topic_favoriters(bbp_get_topic_id()) ; $count = count($subscriptions) ; echo 'number of users subscribed: '.$count; }
Now I only have to look for a way to display my topics and sorted them by numbers of favs! Thanks to you I know there was some major changes with the 2.6 version.
In reply to: Get Number of Favorites & Subscription to a topicHi @robin-w – thanks for your answer.
Here it is – as I’m still learning PHP, I apologize if I did a terrible coding mistake.
I tried some modifications here and there (return, echoing other stuff) but nothing did the trick./* tried to hook the code in my template */ add_action('bbp_template_before_single_topic', 'show_bbp_sub'); function show_bbp_sub() { /* end of it */
/* Original lines from @babblebey */ $topic = bbp_get_topic_id(); $users = get_users() ; $countsub = 0; /* I guess it's echoing only this line */ foreach ($users as $user) { $topicsub_listarray = get_usermeta ($user->id, 'wp__bbp_subscriptions', true) ; $topicsub_list = explode (',' , $topicsub_listarray) ; if (in_array ($topic , $topicsub_list)) $countsub++ ; } echo $countsub; }
Thank you for your help and your patience.
In reply to: Get Number of Favorites & Subscription to a topicHi @babblebey & @robin-w , thank you both for your work on this matter.
I’m trying to do the same on my Bbpress install (not online yet) in order to sort topic by number of “fav mentions”.
I tried your last two codes but it returns “0” (I hooked them on
bbp_template_before_single_topic
and putted them in two separatedfunctions
).Does it still works for you? Did I get it all wrong?
Thank you for your answer. ๐
In reply to: Create new forum topic from a WP post?4 years after your reply, I had to loggin to thank you properly @elhardoum.
Works amazingly for my CPT. Thank you so much!