How to create a custom nested loop in bbPress (WordPress + bbPress plugin)

This is how you do it for WordPress posts:

   $my_query = new WP_Query( "cat=3" );
   if ( $my_query->have_posts() ) { 
       while ( $my_query->have_posts() ) { 
           $my_query->the_post();
           the_content();
       }
   }
   wp_reset_postdata();

I would like to know how to do that in bbPress (say, listing topics).

Related posts

Leave a Reply

2 comments

  1. bbpress has its own query class called BB_Query()

    and it accepts:

        $ints = array(
                'page',     // Defaults to global or number in URI
                'per_page', // Defaults to page_topics
                'tag_id',   // one tag ID
                'favorites' // one user ID
            );
    
        $parse_ints = array(
            // Both
            'post_id',
            'topic_id',
            'forum_id',
    
            // Topics
            'topic_author_id',
            'post_count',
            'tag_count',
    
            // Posts
            'post_author_id',
            'position'
        );
    
        $dates = array(
            'started',  // topic
            'updated',  // topic
            'posted'    // post
        );
    
        $others = array(
            // Both
            'topic',    // one topic name
            'forum',    // one forum name
            'tag',      // one tag name
    
            // Topics
            'topic_author', // one username
            'topic_status', // *normal, deleted, all, parse_int ( and - )
            'open',         // *all, yes = open, no = closed, parse_int ( and - )
            'sticky',       // *all, no = normal, forum, super = front, parse_int ( and - )
            'meta_key',     // one meta_key ( and - )
            'meta_value',   // range
            'topic_title',  // LIKE search.  Understands "doublequoted strings"
            'search',       // generic search: topic_title OR post_text
                            // Can ONLY be used in a topic query
                            // Returns additional search_score and (concatenated) post_text columns
    
            // Posts
            'post_author',  // one username
            'post_status',  // *noraml, deleted, all, parse_int ( and - )
            'post_text',    // FULLTEXT search
                            // Returns additional search_score column (and (concatenated) post_text column if topic query)
            'poster_ip',    // one IPv4 address
    
            // SQL
            'index_hint',   // A full index hint using valid index hint syntax, can be multiple hints an array
            'order_by',     // fieldname
            'order',        // *DESC, ASC
            'count',        // *false = none, true = COUNT(*), found_rows = FOUND_ROWS()
            '_join_type',   // not implemented: For benchmarking only.  Will disappear. join (1 query), in (2 queries)
    
    
    
    // Utility
    //          'append_meta',  // *true, false: topics only
    //          'cache_users',  // *true, false
    //          'cache_topics,  // *true, false: posts only
    //          'post_id_only', // true, *false: this query is only returning post IDs
                'cache_posts'    // not implemented: none, first, last
            );
    
  2. @janoChen – The exact same method can be used to get bbPress forums/topics/replies, as well as there being a few built in functions that act as wrapper functions for them.

    If you can reply back with exactly what kind of information you’re trying to get, I can show you how to build the query. (I.E. you want the 14 most recent public topics, you want the most recent 25 replies by user_id 7, etc…)