bpbbpst_get_support_only_forums

Builds a selectbox with forum set as support only ones.

Description

(string) bpbbpst_get_support_only_forums( (int) $selected = 0, (string) $field_id = '_support_only_forum', (string) $field_name = '_support_only_forums' ); 

Returns (string)

html output

Parameters (3)

0. $selected — Optional. (int)
The forum id previously selected
1. $field_id — Optional. (string) => '_support_only_forum'
Id of the selectbox
2. $field_name — Optional. (string) => '_support_only_forums'
Name of the selectbox

Usage

  1. if ( !function_exists( 'bpbbpst_get_support_only_forums' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddy-bbpress-support-topic/includes/functions.php'; 
  3.  
  4. // the forum id previously selected 
  5. $selected = -1; 
  6.  
  7. // id of the selectbox 
  8. $field_id = '_support_only_forum'; 
  9.  
  10. // name of the selectbox 
  11. $field_name = '_support_only_forums'; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = bpbbpst_get_support_only_forums($selected, $field_id, $field_name); 
  15.  

Defined (1)

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

/includes/functions.php  
  1. function bpbbpst_get_support_only_forums( $selected = 0, $field_id = '_support_only_forum', $field_name = '_support_only_forums' ) { 
  2.  
  3. $query_args = array( 
  4. 'post_type' => bbp_get_forum_post_type(),  
  5. 'posts_per_page' => -1,  
  6. 'meta_query' => array( 
  7. array( 
  8. 'key' => '_bpbbpst_forum_settings',  
  9. 'value' => 2,  
  10. 'type' => 'numeric',  
  11. 'compare' => '=' 
  12. ); 
  13.  
  14. $support_query = new WP_Query( $query_args ); 
  15.  
  16. if ( $support_query->have_posts() ) :?> 
  17.  
  18. <select class="widefat" id="<?php echo $field_id; ?>" name="<?php echo $field_name; ?>"> 
  19.  
  20. <?php while ( $support_query->have_posts() ) : $support_query->the_post() ; ?> 
  21.  
  22. <option value="<?php echo esc_attr( bbp_get_forum_id( $support_query->post->ID ) ) ?>" <?php selected( $support_query->post->ID, $selected ) ?>><?php bbp_forum_title( $support_query->post->ID ) ?></option> 
  23.  
  24. <?php endwhile ; ?> 
  25.  
  26. </select> 
  27.  
  28. <?php wp_reset_postdata(); 
  29.  
  30. else : 
  31. esc_html_e( 'No support only forums were found', 'buddy-bbpress-support-topic' ); 
  32.  
  33. endif;