BuddyDev

Search

[Resolved] Blog Categories For Groups and Custom Taxonomies

  • Participant
    Level: Initiated
    Posts: 19
    Ada on #3557

    Hi Brajesh,

    may I ask if there has been any progress on this. I have been anxious to solve this for quite some time so I can finally go live.

    Many thanks,

    Ada

  • Keymaster
    (BuddyDev Team)
    Posts: 24190
    Brajesh Singh on #3564

    Hi Ada,
    I am sorry. I will post the code tonight.

    Thank you
    Brajesh

  • Keymaster
    (BuddyDev Team)
    Posts: 24190
    Brajesh Singh on #3638

    Hi Ada,
    when you copied the code from the referenced post, you might have used the following code from step 5.

    
    function bcg_custom_forms_args( $args ) {
    	
    	$args['tax'] = array();
    	
    	$cusom_fields = isset( $args['custom_fields'] ) ? $args['custom_fields']: array() ;
    	
    	$group = groups_get_current_group();
    	
    	if( empty( $group ) || empty( $group->id ) ) {
    		return $args;
    	}
    	
    	$cats = bcg_get_categories( $group->id );
    	//if there is no category set
    	if( empty( $cats ) ) {
    		//create if not exists
    		$cats = bcg_custom_create_group_category( $group );
    	}
    	
    	if ( empty( $cats ) ) {
    		return $args;
    	}
    	
    	$cusom_fields['_bcg_selected_category'] = array(
    		'type'		=> 'hidden',
    		'default'	=> $cats[0],
    		'label'		=> ''	
    	);
    	
    	$args['custom_fields'] = $cusom_fields;
    	$args['post_status'] = 'publish';
    	
    	return $args;
    }
    add_filter( 'bcg_form_args', 'bcg_custom_forms_args' );
    
    

    Please change that to this

    
    
    function bcg_custom_forms_args( $args ) {
    
    	$tax = $args['tax'];
    
    	unset( $tax['category'] );//we don't need a box for category
    	$args['tax'] = $tax;
    	$cusom_fields = isset( $args['custom_fields'] ) ? $args['custom_fields']: array() ;
    
    	$group = groups_get_current_group();
    
    	if( empty( $group ) || empty( $group->id ) ) {
    		return $args;
    	}
    
    	$cats = bcg_get_categories( $group->id );
    	//if there is no category set
    	if( empty( $cats ) ) {
    		//create if not exists
    		$cats = bcg_custom_create_group_category( $group );
    	}
    
    	if ( empty( $cats ) ) {
    		return $args;
    	}
    
    	$cusom_fields['_bcg_selected_category'] = array(
    		'type'		=> 'hidden',
    		'default'	=> $cats[0],
    		'label'		=> ''
    	);
    
    	$args['custom_fields'] = $cusom_fields;
    	$args['post_status'] = 'publish';
    
    	return $args;
    }
    add_filter( 'bcg_form_args', 'bcg_custom_forms_args' );
    
    

    We were removing all the taxonomies causing the issue. Updating that section should make it work. Please give it a try. Another small modification may be required if it does not work for you. Please do let me know how it goes with you.

  • Participant
    Level: Initiated
    Posts: 19
    Ada on #3644

    Much appreciate this Brajesh. I have replaced that section and I still see only the label for the allowed taxonomy (“Level”) and still no terms showing. Perhaps the little tweak you mentioned is still necessary.

    I put here all the code and setting that is in place as reference: http://pastebin.com/Cw2AXNE0

    Many thanks,

    Ada

  • Keymaster
    (BuddyDev Team)
    Posts: 24190
    Brajesh Singh on #3657

    Thank you. will update with the code in next 1-2 hours.

  • Keymaster
    (BuddyDev Team)
    Posts: 24190
    Brajesh Singh on #3660

    Hi Ada,
    Thank you. I have made a few more changes in the above function. This should finally do our job. Please check if it works or not?

    
    
    function bcg_custom_forms_args( $args ) {
    
    	$tax = $args['tax'];
    
    	unset( $tax['category'] );//we don't need a box for category
    
    	foreach( $tax as $taxonomy => $details ) {
    		$tax[$taxonomy]['include'] = get_terms( $taxonomy, array('fields' => 'ids', 'get' => 'all') );
    	}
    
    	$args['tax'] = $tax;
    
    	$cusom_fields = isset( $args['custom_fields'] ) ? $args['custom_fields']: array() ;
    
    	$group = groups_get_current_group();
    
    	if( empty( $group ) || empty( $group->id ) ) {
    		return $args;
    	}
    
    	$cats = bcg_get_categories( $group->id );
    	//if there is no category set
    	if( empty( $cats ) ) {
    		//create if not exists
    		$cats = bcg_custom_create_group_category( $group );
    	}
    
    	if ( empty( $cats ) ) {
    		return $args;
    	}
    
    	$cusom_fields['_bcg_selected_category'] = array(
    		'type'      => 'hidden',
    		'default'   => $cats[0],
    		'label'     => ''
    	);
    
    	$args['custom_fields'] = $cusom_fields;
    	$args['post_status'] = 'publish';
    
    	return $args;
    }
    add_filter( 'bcg_form_args', 'bcg_custom_forms_args' );
    
    

    Thank you
    Brajesh

  • Participant
    Level: Initiated
    Posts: 19
    Ada on #3679

    This is amazing – it works as expected! Thank you very much Brajesh for all the effort and expert advice.

    Btw, the notification on the forum seems not to work sometime – I just saw your addition.

    Am up to yet another membership round if my questions become a bit hairy. For now all the best and thank you again.

    Ada

  • Keymaster
    (BuddyDev Team)
    Posts: 24190
    Brajesh Singh on #3680

    Hi Ada,
    Thank you for the kind words. I am glad we have finally got it working.

    Have always appreciated your support. All the best with your project.

    Regards
    Brajesh

The topic ‘ [Resolved] Blog Categories For Groups and Custom Taxonomies’ is closed to new replies.

This topic is: resolved