Skip to:
Content
Pages
Categories
Search
Top
Bottom

Importing Categories to Groups


  • mgrmn
    Participant

    @mgrmn

    Ok, I am trying to create groups importing the wp categories (not the subs) using this code, after which i would like to insert new posts created in that category being added to the activity stream. I figured that using the same cat id as group id, would be the simple way of adding it to the group activity stream without to much trouble. (tell me if I am wrong)

    Question 1: Now i am getting the categories just fine. but the part creating group is not working.
    Question 2: Where can I find the part that actually creates the activity after a post has been created.

    $categories = get_categories( $args );
    foreach ( $categories as $category ) {
    	if ($category->parent == '0') {
    	groups_create_group( array( 'group_id' => $category->cat_ID, 
    				    'name' => $category->cat_name, 
    				    'description' => $category->description, 
    				    'slug' => $category->slug, 
    				    'date_created' => bp_core_current_time(), 
    				    'status' => 'public' ) );
    	groups_update_groupmeta( $category->cat_ID, 'total_member_count', 1 );
    	groups_update_groupmeta( $category->cat_ID, 'last_activity', bp_core_current_time() );	
    	} else  { 
    		// I do not want subcategories for now
    	}
    }
Viewing 4 replies - 1 through 4 (of 4 total)

  • mgrmn
    Participant

    @mgrmn

    Found problem for my first question, dont have the answer it though

    Undefined property: BP_Groups_Component::$table_name


    mgrmn
    Participant

    @mgrmn

    Can somebody tell me where I can find the part the records the activity for posts ?

    I would like to modify the part that inserts activity when a post is created.


    mgrmn
    Participant

    @mgrmn

    I have this within the bp_blogs_record_post function. Ofcourse its not working, can somebody help me on the right track please, thank you very much $cat_id is same id as the group id.

    `bp_activity_add( array( ‘user_id’ =>’2′,
    ‘action’ => ‘New Post’,
    ‘content’ => ‘<a href=”‘ . $post_permalink . ‘”>’ . $post->post_title . ‘</a>’,
    ‘primary_link’ => $post_permalink,
    ‘component’ => ‘groups’,
    ‘type’ => ‘activity_update’,
    ‘item_id’ => $cat_id,
    ‘recorded_time’ => bp_core_current_time(),
    ‘hide_sitewide’ => false ) );`


    mgrmn
    Participant

    @mgrmn

    Got it 🙂 problem was the $cat_id

    			$category = get_the_category($post_id); 
    			bp_activity_add( array( 'user_id' => (int) $post->post_author, 
    										 'action' => apply_filters( 'bp_blogs_activity_new_post_action',       $activity_action,  $post, $post_permalink ), 
    										 'content' => '<a href="' . $post_permalink . '">' . $post->post_title . '</a>', 
    										 'primary_link' => $post_permalink, 
    										 'component' => 'groups', 
    										 'type' => 'activity_update', 
    										 'item_id' => $category[0]->cat_ID, 
    										 'recorded_time' => bp_core_current_time(), 
    										 'hide_sitewide' => false ) );

    [solved]

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Importing Categories to Groups’ is closed to new replies.
Skip to toolbar