bp_forums_get_forum_topics

Fetch a set of forum topics.

Description

(array) bp_forums_get_forum_topics( (string) $args = '' ); 

Returns (array)

Found topics.

Parameters (1)

0. $args — Optional. (string) => ''
The args.

Options

  • type (string) => ''

    Order or filter type. Default: newest..

  • forum_id (int) => 0

    Pass a forum ID to limit results to topics associated with that forum.

  • user_id (int) => 0

    Pass a user ID to limit results to topics belonging to that user.

  • page (int) => 0

    Number of the results page to return. Default: 1.

  • per_page (int) => 0

    Number of results to return per page. Default: 15.

  • offset (int) => 0

    Numeric offset for results.

  • number (int) => 0

    Amount to query for.

  • exclude (array) => null

    Topic IDs to exclude.

  • show_stickies (string) => ''

    Whether to show sticky topics.

array(

    /**
     * Order or filter type. Default: 'newest'.
     *
     * @type string
     * @default ''
     */
    'type' => '',

    /**
     * Optional. Pass a forum ID to limit results to topics associated with that forum.
     *
     * @type int
     * @optional
     */
    'forum_id' => 0,

    /**
     * Optional. Pass a user ID to limit results to topics belonging to that user.
     *
     * @type int
     * @optional
     */
    'user_id' => 0,

    /**
     * Optional. Number of the results page to return. Default: 1.
     *
     * @type int
     * @optional
     */
    'page' => 0,

    /**
     * Optional. Number of results to return per page. Default: 15.
     *
     * @type int
     * @optional
     */
    'per_page' => 0,

    /**
     * Optional. Numeric offset for results.
     *
     * @type int
     * @optional
     */
    'offset' => 0,

    /**
     * Amount to query for.
     *
     * @type int
     */
    'number' => 0,

    /**
     * Optional. Topic IDs to exclude.
     *
     * @type array
     * @default null
     * @optional
     */
    'exclude' => null,

    /**
     * Whether to show sticky topics.
     *
     * @type string
     * @default ''
     */
    'show_stickies' => ''
);        


Usage

  1. if ( !function_exists( 'bp_forums_get_forum_topics' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bp-forums-functions.php'; 
  3.  
  4. // The args. 
  5. $args = array( 
  6. 'type' => '', 
  7. 'forum_id' => 0, 
  8. 'user_id' => 0, 
  9. 'page' => 0, 
  10. 'per_page' => 0, 
  11. 'offset' => 0, 
  12. 'number' => 0, 
  13. 'exclude' => null, 
  14. 'show_stickies' => '' 
  15. ); 
  16.  
  17. // NOTICE! Understand what this does before running. 
  18. $result = bp_forums_get_forum_topics($args); 
  19.  

Defined (1)

The function is defined in the following location(s).

/bp-forums/bp-forums-functions.php  
  1. function bp_forums_get_forum_topics( $args = '' ) { 
  2.  
  3. /** This action is documented in bp-forums/bp-forums-screens.php */ 
  4.  
  5. $r = wp_parse_args( $args, array( 
  6. 'type' => 'newest',  
  7. 'forum_id' => false,  
  8. 'user_id' => false,  
  9. 'page' => 1,  
  10. 'per_page' => 15,  
  11. 'offset' => false,  
  12. 'number' => false,  
  13. 'exclude' => false,  
  14. 'show_stickies' => 'all',  
  15. 'filter' => false // If $type = tag then filter is the tag name, otherwise it's terms to search on. 
  16. ) ); 
  17. extract( $r, EXTR_SKIP ); 
  18.  
  19. if ( class_exists( 'BB_Query' ) ) { 
  20. switch ( $type ) { 
  21. case 'newest': 
  22. $query = new BB_Query( 'topic', array( 'forum_id' => $forum_id, 'topic_author_id' => $user_id, 'per_page' => $per_page, 'page' => $page, 'number' => $per_page, 'exclude' => $exclude, 'topic_title' => $filter, 'sticky' => $show_stickies, 'offset' => $offset, 'number' => $number ), 'get_latest_topics' ); 
  23. $topics =& $query->results; 
  24. break; 
  25.  
  26. case 'popular': 
  27. $query = new BB_Query( 'topic', array( 'forum_id' => $forum_id, 'topic_author_id' => $user_id, 'per_page' => $per_page, 'page' => $page, 'order_by' => 't.topic_posts', 'topic_title' => $filter, 'sticky' => $show_stickies, 'offset' => $offset, 'number' => $number ) ); 
  28. $topics =& $query->results; 
  29. break; 
  30.  
  31. case 'unreplied': 
  32. $query = new BB_Query( 'topic', array( 'forum_id' => $forum_id, 'topic_author_id' => $user_id, 'post_count' => 1, 'per_page' => $per_page, 'page' => $page, 'order_by' => 't.topic_time', 'topic_title' => $filter, 'sticky' => $show_stickies, 'offset' => $offset, 'number' => $number ) ); 
  33. $topics =& $query->results; 
  34. break; 
  35.  
  36. case 'tags': 
  37. $query = new BB_Query( 'topic', array( 'forum_id' => $forum_id, 'topic_author_id' => $user_id, 'tag' => $filter, 'per_page' => $per_page, 'page' => $page, 'order_by' => 't.topic_time', 'sticky' => $show_stickies, 'offset' => $offset, 'number' => $number ) ); 
  38. $topics =& $query->results; 
  39. break; 
  40. } else { 
  41. $topics = array(); 
  42.  
  43. /** 
  44. * Filters the found forum topics for provided arguments. 
  45. * @since 1.1.0 
  46. * @param array $topics Array of found topics. Passed by reference. 
  47. * @param array $r Array of parsed arguments for query. Passed by reference. 
  48. */ 
  49. return apply_filters_ref_array( 'bp_forums_get_forum_topics', array( &$topics, &$r ) );