BuddyDev

Search

[Resolved] Categories – Dropdown Rather than Select

  • Participant
    Level: Initiated
    Posts: 6
    Cameron on #53138

    Hello,

    I see that if I enable category selection with a post, each category is listed on the form with a checkbox next each. This is too long as I have many.

    Can this be changed? If so, how? Ideally, I’d like a dropdown select with only one selection possible.

    Thanks

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #53139

    Hello Cameron,

    Please try the following code it will list all taxonomies in dropdown.

    
    
    add_filter( 'buddyblog_post_form_settings', function ( $settings ) {
    
    	if ( buddyblog_get_option( 'enable_taxonomy' ) ) {
    		$taxonomies = array();
    		$tax        = buddyblog_get_option( 'allowed_taxonomies' );
    
    		if ( ! empty( $tax ) ) {
    
    			foreach ( (array) $tax as $tax_name ) {
    				$taxonomies[ $tax_name ] = array(
    					'taxonomy'  => $tax_name,
    					'view_type' => 'dd',
    				);
    
    			}
    		}
    
    		if ( ! empty( $taxonomies ) ) {
    			$settings['tax'] = $taxonomies;
    		}
    	}
    
    	return $settings;
    } );
    
    

    Place this code in your ‘bp-custom.php’ file.

    For ref: https://buddydev.com/docs/buddypress-guides/what-is-bp-custom-php/

    Regards
    Ravi

  • Participant
    Level: Initiated
    Posts: 6
    Cameron on #53140

    That worked and thank you.

    For those of you that are new to the ‘bp-custom.php’ file…

    Don’t forget to encase everything with <? ?>. Otherwise, Ravi’s code won’t work.

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #53144

    Hello Cameron,

    Thank you for the acknowledgement. I am glad that I could help.

    Note: Please don’t use <? ?> it is shorthand for php. Use like the following

    
    <?php
    
    // Your code goes here.
    
    

    Regards
    Ravi

  • Participant
    Level: Initiated
    Posts: 6
    Cameron on #53146

    Will do and thank!

The topic ‘ [Resolved] Categories – Dropdown Rather than Select’ is closed to new replies.

This topic is: resolved