BuddyDev

Search

Group Categories and restricting which ones display.


  • Participant
    Level: Initiated
    Posts: 12
    Phil B on #3535

    Hi Ravi,

    I wont have chance to test it until Monday anyway so there is no immediate rush. But it is much appreciated. Thank you. Il mark this as resolved once I’ve tested.

    Many thanks

    Phil


  • Keymaster
    (BuddyDev Team)
    Posts: 13864
    Brajesh Singh on #3541

    Hi Phil,
    Please use the following code to assign a default category.

    
    
    //set default categorywhen post is being saved
    function bcg_set_default_category_to_post( $post_id ) {
    	
    	$post = get_post( $post_id );
    	
    	if ( ! $post ) {
    		return ;
    	}
    	
    	$terms = wp_get_object_terms( $post_id, 'category' );
    	
    	if ( empty( $terms ) || ( count( $terms ) == 1 && $terms[0]->term_id == 1 ) ) {
    		
    		$term_id = 32;//please change it with the default term you want to assign
    		
    		wp_set_object_terms( $post->ID, $term_id, 'category' );
    		
    	}
    	
    }
    
    add_action( 'bsfep_post_saved', 'bcg_set_default_category_to_post' );
    
    

    Please make sure to change $term_id to your choice of default term id.

    Hope that helps

    Regards
    Brajesh


  • Participant
    Level: Initiated
    Posts: 12
    Phil B on #3556

    Hi Brajesh,

    Thanks for the code I just have a couple of questions.

    Will this auto select the correct category for each group? or just the one category based on the ID?

    I have users who are put into groups depending on who their coach is. And I would just like them to automatically be posted to the relevant group.

    Also where would I find out the Term_id?


  • Keymaster
    (BuddyDev Team)
    Posts: 13864
    Brajesh Singh on #3565

    Hi Phil,
    Thank you for asking.
    No, It will not auto select for each group.

    You will need to assign different term_id for different groups.

    Term id is the category id. You can see it from the Dashboard->Posts->Categories screen.

    Hope that helps.


  • Participant
    Level: Initiated
    Posts: 12
    Phil B on #3617

    Hi Brajesh,

    I really appreciate this code, however I would need to be able to auto select the category based on the group they are in. How would that work? I’m afraid my PHP is not very good and I’m not sure what I would need to edit in order to do this.

    Thanks for your patience Brajesh

    Regards

    Phil


  • Keymaster
    (BuddyDev Team)
    Posts: 13864
    Brajesh Singh on #3618

    Hi Phil,
    No problem.
    There are two things that can be done here:-
    1. Easy way:- Will it work if we assign one of the allowed categories for the group automatically if no group is assigned.

    2. Or, It will be a little bit complicated but we do plan to have this feature in future, Allow group admins to select a default category(or term) which will be used when no category is assigned. it will take some time though.

    Please let me know which one suits you better.

    Thank you
    Brajesh


  • Participant
    Level: Initiated
    Posts: 12
    Phil B on #3624

    Hi,

    The second option seems like the best, as I don’t want the members to be able to post In the wrong categories.

    Would it help if I explained what happens on the website? Basically…..

    It is a golf website where someone can sign up for lessons, the lessons are held across the country by different coaches.

    What happens at the moment is when a new member signs up they are put into a ‘love.golfers’ group and a group for their relevant coach, we’ll call it ‘phils group’ for now.

    As I say each coach has their own group and eventually we would like to add a lot more coaches, so as the list gets bigger the more likely it will be that someone could end up in the wrong category.

    What I would like is for these members to be able to post in their respective groups but also make it impossible for them to select the wrong category.

    The idea behind the groups blogs is that the members can communicate with the coach and each other in a private environment so they can ask for help and et cetera.

    Sorry if I’m confusing things more. I think the second option would help the most even if it means waiting for an update to the Blog Categories plugin. It shouldn’t cause too many issues now as the website is still relatively new.

    Many thanks Brajesh

    Phil

You must be logged in to reply to this topic.

This topic is: not resolved
Subscribe