BuddyDev

Search

[Resolved] Buddyblog – How to limit Categories and Tags?

  • Participant
    Level: Initiated
    Posts: 3
    Ken on #6038

    So I found an old post about how to limit categories…but I’m not sure how to limit categories and tags? Once I use the code, it erases the ability to select any tags while making a blog. How can I choose what categories and tags are allowed from the front end?

    Here is the code that works great with categories but I’m stumped on the blog…

    function buddyblog_show_custom_cats( $settings ) {
    $tax = array();

    $tax[‘category’] = array(

    ‘taxonomy’ => ‘category’,
    ‘view_type’ => ‘dd’,
    ‘child_of’ => 29, //CHAGE It with the correct ID,
    ‘orderby’ => ‘slug’,
    ‘order’ => ‘ASC’
    );

    $settings[‘tax’] = $tax;

    return $settings;
    }

  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #6047

    Hi Ken,
    Thank you for posting.

    Please allow me to post the code tomorrow.

    Thank you
    Brajesh

  • Participant
    Level: Initiated
    Posts: 3
    Ken on #6067

    That would be awesome. Thank you Brajesh!

  • Participant
    Level: Initiated
    Posts: 3
    Ken on #6178

    Hey Brajesh! Any word on how I might be able to code this? Much appreciated man!

  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #6184

    Hi Ken,
    I am sorry I missed it. I will post the code today(Around noon PST).

    Thank you
    Brajesh

  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #6190

    Hi Ken,
    hope you are doing fine.

    Please use the following code and modify the term ids with your own to include only them.

    
    
    function buddyblog_limit_terms( $settings ) {
    
    	if ( ! isset( $settings['tax'] ) ) {
    		return $settings;
    	}
    
    	$tax = $settings['tax']; //it is multi dimensional array
    
    	$taxonomy = 'category';//name of taxonomy
    
    	// Array  of term ids to include.
    	$terms = array(1, 53 ); //term ids
    
    	if( ! isset( $tax[ $taxonomy ] ) ) {
    		$tax[ $taxonomy ] = array();
    	}
    
    	$tax[ $taxonomy ]['include'] = $terms;
    
    	//update settings
    	$settings['tax'] = $tax;
    	
    	return $settings;
    
    }
    add_filter( 'buddyblog_post_form_settings', 'buddyblog_limit_terms' );
    

    Hope that helps.

    Brajesh

  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #6191

    Please put the code in bp-custom.php .

  • Participant
    Level: Initiated
    Posts: 3
    Ken on #6194

    Hey, this is better! Thank you sir! My tags option reappeared..but is there a way I can also limit the tags like I can with categories?

  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #6200

    Hi Ken,
    Sure we can. here is the updated code from the above example.

    
    
    function buddyblog_limit_terms( $settings ) {
    
    	if ( ! isset( $settings['tax'] ) ) {
    		return $settings;
    	}
    
    	$tax = $settings['tax']; //it is multi dimensional array
    
    	$tax_terms = array(
    		'category'=> array(1, 53 ), // tax_name=> term_ids
    		'post_tag' => array( 7, 9 ), //add as you please, //you can add other taxonomy too
    	);
    
    	foreach ( $tax_terms as $taxonomy => $terms ) {
    
    		if ( ! isset( $tax[ $taxonomy ] ) ) {
    			$tax[ $taxonomy ] = array();
    		}
    
    		$tax[ $taxonomy ]['include'] = $terms;
    	}
    
    	//update settings
    	$settings['tax'] = $tax;
    
    	return $settings;
    
    }
    add_filter( 'buddyblog_post_form_settings', 'buddyblog_limit_terms' );
    
    

    It is simplified to use multiple taxonomies.

    Hope that helps.

The topic ‘ [Resolved] Buddyblog – How to limit Categories and Tags?’ is closed to new replies.

This topic is: resolved