bbp_get_dropdown( mixed $args = '' )

Output a select box allowing to pick which forum/topic a new topic/reply belongs in.

Description

Parameters

$args

(Optional) The function supports these args: - post_type: Post type, defaults to bbp_get_forum_post_type() (bbp_forum) - selected: Selected ID, to not have any value as selected, pass anything smaller than 0 (due to the nature of select box, the first value would of course be selected - though you can have that as none (pass 'show_none' arg)) - orderby: Defaults to 'menu_order title' - post_parent: Post parent. Defaults to 0 - post_status: Which all post_statuses to find in? Can be an array or CSV of publish, category, closed, private, spam, trash (based on post type) - if not set, these are automatically determined based on the post_type - posts_per_page: Retrieve all forums/topics. Defaults to -1 to get all posts - walker: Which walker to use? Defaults to BBP_Walker_Dropdown - select_id: ID of the select box. Defaults to 'bbp_forum_id' - tab: Tabindex value. False or integer - options_only: Show only <options>? No <select>? - show_none: Boolean or String __( '(No Forum)', 'buddyboss' ) - disable_categories: Disable forum categories and closed forums? Defaults to true. Only for forums and when the category option is displayed.

Default value: ''

Return

(string) The dropdown

Source

File: bp-forums/common/template.php

1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
function bbp_get_dropdown( $args = '' ) {
 
    /** Arguments *********************************************************/
 
    // Parse arguments against default values
    $r = bbp_parse_args( $args,
        array(
            'post_type'             => bbp_get_forum_post_type(),
            'post_parent'           => null,
            'post_status'           => null,
            'selected'              => 0,
            'exclude'               => array(),
            'numberposts'           => - 1,
            'orderby'               => 'menu_order title',
            'order'                 => 'ASC',
            'walker'                => '',
 
            // Output-related
            'select_id'             => 'bbp_forum_id',
            'tab'                   => bbp_get_tab_index(),
            'options_only'          => false,
            'show_none'             => false,
            'show_none_default_val' => '',
            'disable_categories'    => true,
            'disabled'              => '',
        ),
        'get_dropdown' );
 
    if ( empty( $r['walker'] ) ) {
        $r['walker']            = new BBP_Walker_Dropdown();
        $r['walker']->tree_type = $r['post_type'];
    }
 
    // Force 0
    if ( is_numeric( $r['selected'] ) && $r['selected'] < 0 ) {
        $r['selected'] = 0;
    }
 
    // Force array
    if ( !empty( $r['exclude'] ) && !is_array( $r['exclude'] ) ) {
        $r['exclude'] = explode( ',', $r['exclude'] );
    }
 
    /** Setup variables ***************************************************/
 
    $retval = '';
    $posts  = get_posts( array(
        'post_type'          => $r['post_type'],
        'post_status'        => $r['post_status'],
        'exclude'            => $r['exclude'],
        'post_parent'        => $r['post_parent'],
        'numberposts'        => $r['numberposts'],
        'orderby'            => $r['orderby'],
        'order'              => $r['order'],
        'walker'             => $r['walker'],
        'disable_categories' => $r['disable_categories']
    ) );
 
    /** Drop Down *********************************************************/
 
    // Build the opening tag for the select element
    if ( empty( $r['options_only'] ) ) {
 
        // Should this select appear disabled?
        $disabled  = disabled( isset( bbpress()->options[ $r['disabled'] ] ), true, false );
 
        // Setup the tab index attribute
        $tab       = !empty( $r['tab'] ) ? ' tabindex="' . intval( $r['tab'] ) . '"' : '';
 
        // Open the select tag
        $retval   .= '<select name="' . esc_attr( $r['select_id'] ) . '" id="' . esc_attr( $r['select_id'] ) . '"' . $disabled . $tab . '>' . "\n";
    }
 
    // Display a leading 'no-value' option, with or without custom text
    if ( !empty( $r['show_none'] ) || !empty( $r['none_found'] ) ) {
 
        // Set none field value.
        $val = $r['show_none_default_val'];
 
        // Open the 'no-value' option tag
        $retval .= "\t<option value=\"$val\" class=\"level-0\">";
 
        // Use deprecated 'none_found' first for backpat
        if ( ! empty( $r['none_found'] ) && is_string( $r['none_found'] ) ) {
            $retval .= esc_html( $r['none_found'] );
 
        // Use 'show_none' second
        } elseif ( ! empty( $r['show_none'] ) && is_string( $r['show_none'] ) ) {
            $retval .= esc_html( $r['show_none'] );
 
        // Otherwise, make some educated guesses
        } else {
 
            // Switch the response based on post type
            switch ( $r['post_type'] ) {
 
                // Topics
                case bbp_get_topic_post_type() :
                    $retval .= esc_html__( 'No discussions available', 'buddyboss' );
                    break;
 
                // Forums
                case bbp_get_forum_post_type() :
                    $retval .= esc_html__( 'No forums available', 'buddyboss' );
                    break;
 
                // Any other
                default :
                    $retval .= esc_html__( 'None available', 'buddyboss' );
                    break;
            }
        }
 
        // Close the 'no-value' option tag
        $retval .= '</option>';
    }
 
    // Items found so walk the tree
    if ( !empty( $posts ) ) {
        add_filter( 'list_pages', 'bbp_reply_attributes_meta_box_discussion_reply_title', 999, 2 );
        unset( $r['walker']);
        $retval .= walk_page_dropdown_tree( $posts, 0, $r );
        remove_filter( 'list_pages', 'bbp_reply_attributes_meta_box_discussion_reply_title', 999, 2  );
    }
 
    // Close the selecet tag
    if ( empty( $r['options_only'] ) ) {
        $retval .= '</select>';
    }
 
    return apply_filters( 'bbp_get_dropdown', $retval, $r );
}

Changelog

Changelog
Version Description
bbPress (r2746) Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.