0

I have bbpress installed as a plugin in a wordpress site and want to display the total amount of forums, topics and replies on the worpress home page but cannot seem to figure this out.

The following piece of code displays a table similar to the default forms display which contains this information but cant seem to figure out to extract this information.

bbp_set_query_name('load_forum_details');
if ( bbp_has_forums() ) :
    bbp_get_template_part( 'loop', 'forums' );
endif;
bbp_reset_query_name();

has anyone any ideas?

regards

Luke Snowden
  • 4,056
  • 2
  • 37
  • 70

3 Answers3

1
<?php $forum_id = 12; ?>
<?php bbp_forum_topic_count($forum_id); //Show topic count ?>
<?php bbp_show_lead_topic($forum_id) ? bbp_forum_reply_count($forum_id) : bbp_forum_post_count($forum_id); //Show reply count ?>

This code to show topic count and reply count of forum with id =12

Hope useful for you

Sakata Gintoki
  • 1,817
  • 16
  • 23
1

VERY late to the party, but (since version 2.5) Wordpress has a function wp_count_posts() that will count any (custom) post type.

So you can just use $forumCount = wp_count_posts('forum)->publish; and echo $forumCount;.

Found in the accepted answer on this post: https://wordpress.stackexchange.com/questions/26559/counting-the-number-of-posts-custom-post-type-query-problem

Ralph Smit
  • 71
  • 1
  • 5
0

Think I've managed to do this:

function bbpress_summary() {
    global $wpdb;
    return array(
        'forum_count' => $wpdb->get_var("SELECT COUNT(post_id) FROM $wpdb->postmeta WHERE meta_key = '_bbp_total_topic_count'"),
        'topic_count' => $wpdb->get_var("SELECT COUNT(post_id) FROM $wpdb->postmeta WHERE meta_key = '_bbp_topic_id' AND `post_id` = `meta_value`"),
        'thread_count' => $wpdb->get_var("SELECT COUNT(post_id) FROM $wpdb->postmeta WHERE meta_key = '_bbp_topic_id'"),
        'user_count' => $wpdb->get_var("SELECT COUNT(user_id) FROM $wpdb->usermeta WHERE meta_key = 'wp_user_level'")
    );
}
Luke Snowden
  • 4,056
  • 2
  • 37
  • 70