is there any way to list all forums into one page?

I see there are shortcodes for use one forum into one page like [forum id=”2″]

But is there any way to create a forum list?

Using a list of shortcodes like:

[forum id=”1″]

[forum id=”2″]

[forum id=”3″]

Does not works, because I want a forum list where you can see a list of forums, and information about how much posts has each forum, etc

  • Ash
    • WordPress Hacker

    Hello dacstyle

    Please try the following code:

    add_shortcode( 'forum_list', function() {
    global $wpdb;
    if ( ! empty( $wpdb->base_prefix ) ) {
    $db_prefix = $wpdb->base_prefix;
    } else {
    $db_prefix = $wpdb->prefix;

    $query = "SELECT * FROM " . $db_prefix . "forums WHERE forum_blog_ID = %d ORDER BY forum_ID DESC";
    $tmp_forums = $wpdb->get_results( $wpdb->prepare( $query, $wpdb->blogid ), ARRAY_A );

    $html = "<table cellpadding='3' cellspacing='3' width='100%' class='widefat'>
    <th scope='col'>ID</th>
    <th scope='col'>Name</th>
    <tbody id='the-list'>

    foreach( $tmp_forums as $tmp_forum ){
    $html .= "<tr>";
    $html .= "<td valign='top'><strong>" . (int)$tmp_forum['forum_ID'] . "</strong></td>";
    $html .= "<td valign='top'>" . esc_html(stripslashes($tmp_forum['forum_name'])) . "</td>";
    $html .= "</tr>";

    $html .= '</tbody></table>';

    return $html;
    } );

    You can use this code in your theme’s functions.php if the theme is not changed. Otherwise mu-plugin is the best option. To create a mu-plugin, go to wp-content/mu-plugins folder. If there is no mu-plugins folder then, create one. Now, inside the mu-plugins folder create file with name anything.php (make sure file extension is .php). Now start with a <?php tag and then put the above code.

    Then use this shortcode in any page:


    Hope it helps! Please feel free to ask more questions if you have any.

    Have a nice day!



Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.