bbp_has_replies

The main reply loop.

Description

(object) bbp_has_replies( (string) $args = '' ); 

WordPress makes this easy for us

Returns (object)

Multidimensional array of reply information

Parameters (1)

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

Options

    ;        


    Usage

    1. if ( !function_exists( 'bbp_has_replies' ) ) { 
    2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/replies/template.php'; 
    3.  
    4. // The args. 
    5. $args = ''; 
    6.  
    7. // NOTICE! Understand what this does before running. 
    8. $result = bbp_has_replies($args); 
    9.  

    Defined (1)

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

    /includes/replies/template.php  
    1. function bbp_has_replies( $args = '' ) { 
    2. global $wp_rewrite; 
    3.  
    4. /** Defaults **************************************************************/ 
    5.  
    6. // Other defaults 
    7. $default_reply_search = !empty( $_REQUEST['rs'] ) ? $_REQUEST['rs'] : false; 
    8. $default_post_parent = ( bbp_is_single_topic() ) ? bbp_get_topic_id() : 'any'; 
    9. $default_thread_replies = (bool) ( bbp_is_single_topic() && bbp_thread_replies() ); 
    10.  
    11. // Default query args 
    12. $default = array( 
    13. 'post_type' => $default_post_type, // Only replies 
    14. 'post_parent' => $default_post_parent, // Of this topic 
    15. 'posts_per_page' => bbp_get_replies_per_page(), // This many 
    16. 'paged' => bbp_get_paged(), // On this page 
    17. 'orderby' => 'date', // Sorted by date 
    18. 'order' => 'ASC', // Oldest to newest 
    19. 'hierarchical' => $default_thread_replies, // Hierarchical replies 
    20. 'ignore_sticky_posts' => true, // Stickies not supported 
    21. 's' => $default_reply_search, // Maybe search 
    22. ); 
    23.  
    24. // What are the default allowed statuses (based on user caps) 
    25. if ( bbp_get_view_all() ) { 
    26.  
    27. // Default view=all statuses 
    28. $post_statuses = array( 
    29. ); 
    30.  
    31. // Add support for private status 
    32. if ( current_user_can( 'read_private_replies' ) ) { 
    33. $post_statuses[] = bbp_get_private_status_id(); 
    34.  
    35. // Join post statuses together 
    36. $default['post_status'] = implode( ', ', $post_statuses ); 
    37.  
    38. // Lean on the 'perm' query var value of 'readable' to provide statuses 
    39. } else { 
    40. $default['perm'] = 'readable'; 
    41.  
    42. /** Setup *****************************************************************/ 
    43.  
    44. // Parse arguments against default values 
    45. $r = bbp_parse_args( $args, $default, 'has_replies' ); 
    46.  
    47. // Set posts_per_page value if replies are threaded 
    48. $replies_per_page = $r['posts_per_page']; 
    49. if ( true === $r['hierarchical'] ) { 
    50. $r['posts_per_page'] = -1; 
    51.  
    52. // Get bbPress 
    53. $bbp =bbpress); 
    54.  
    55. // Call the query 
    56. $bbp->reply_query = new WP_Query( $r ); 
    57.  
    58. // Add pagination values to query object 
    59. $bbp->reply_query->posts_per_page = $replies_per_page; 
    60. $bbp->reply_query->paged = $r['paged']; 
    61.  
    62. // Never home, regardless of what parse_query says 
    63. $bbp->reply_query->is_home = false; 
    64.  
    65. // Reset is_single if single topic 
    66. if ( bbp_is_single_topic() ) { 
    67. $bbp->reply_query->is_single = true; 
    68.  
    69. // Only add reply to if query returned results 
    70. if ( (int) $bbp->reply_query->found_posts ) { 
    71.  
    72. // Get reply to for each reply 
    73. foreach ( $bbp->reply_query->posts as &$post ) { 
    74.  
    75. // Check for reply post type 
    76. if ( bbp_get_reply_post_type() === $post->post_type ) { 
    77. $reply_to = bbp_get_reply_to( $post->ID ); 
    78.  
    79. // Make sure it's a reply to a reply 
    80. if ( empty( $reply_to ) || ( bbp_get_reply_topic_id( $post->ID ) === $reply_to ) ) { 
    81. $reply_to = 0; 
    82.  
    83. // Add reply_to to the post object so we can walk it later 
    84. $post->reply_to = $reply_to; 
    85.  
    86. // Only add pagination if query returned results 
    87. if ( (int) $bbp->reply_query->found_posts && (int) $bbp->reply_query->posts_per_page ) { 
    88.  
    89. // If pretty permalinks are enabled, make our pagination pretty 
    90. if ( $wp_rewrite->using_permalinks() ) { 
    91.  
    92. // User's replies 
    93.  
    94. // Root profile page 
    95. } elseif ( bbp_is_single_user() ) { 
    96.  
    97. // Page or single post 
    98. } elseif ( is_page() || is_single() ) { 
    99. $base = get_permalink(); 
    100.  
    101. // Single topic 
    102. } else { 
    103. $base = get_permalink( bbp_get_topic_id() ); 
    104.  
    105. $base = trailingslashit( $base ) . user_trailingslashit( $wp_rewrite->pagination_base . '/%#%/' ); 
    106.  
    107. // Unpretty permalinks 
    108. } else { 
    109. $base = add_query_arg( 'paged', '%#%' ); 
    110.  
    111. // Figure out total pages 
    112. if ( true === $r['hierarchical'] ) { 
    113. $walker = new BBP_Walker_Reply; 
    114. $total_pages = ceil( (int) $walker->get_number_of_root_elements( $bbp->reply_query->posts ) / (int) $replies_per_page ); 
    115. } else { 
    116. $total_pages = ceil( (int) $bbp->reply_query->found_posts / (int) $replies_per_page ); 
    117.  
    118. // Add pagination to query object 
    119. $bbp->reply_query->pagination_links = paginate_links( apply_filters( 'bbp_replies_pagination', array( 
    120. 'base' => $base,  
    121. 'format' => '',  
    122. 'total' => $total_pages,  
    123. 'current' => (int) $bbp->reply_query->paged,  
    124. 'prev_text' => is_rtl() ? '→' : '←',  
    125. 'next_text' => is_rtl() ? '←' : '→',  
    126. 'mid_size' => 1,  
    127. 'add_args' => ( bbp_get_view_all() ) ? array( 'view' => 'all' ) : false 
    128. ) ) ); 
    129.  
    130. // Remove first page from pagination 
    131. if ( $wp_rewrite->using_permalinks() ) { 
    132. $bbp->reply_query->pagination_links = str_replace( $wp_rewrite->pagination_base . '/1/', '', $bbp->reply_query->pagination_links ); 
    133. } else { 
    134. $bbp->reply_query->pagination_links = str_replace( '&paged=1', '', $bbp->reply_query->pagination_links ); 
    135.  
    136. // Return object 
    137. return apply_filters( 'bbp_has_replies', $bbp->reply_query->have_posts(), $bbp->reply_query );