Your cart is currently empty!
Use Gravity Forms to Assign Group To Custom Content
—
by
I am using Gravity Forms to generate posts of a custom content type. I would like to assign the group via this gravity form. When mapping the gravity forms fields to the custom content fields, I see ‘groups-read’ as an option, but the group name is not being passed to the post on submission. Not sure what I’m missing. Another member in the forums had a similar situation, and it was suggested to use the following;
Groups_User_Group::create( array( ‘user_id’ => $user_id, ‘group_id’ => $group_id ) );
I believe this snippet assigns a user to a group. How do I assign content to a group?
Posted in Groups
Comments
3 responses to “Use Gravity Forms to Assign Group To Custom Content”
Perfect!
That did the trick. Thank you for your help.
Hi Ashwin,
Your notice is correct, the snippet you shared will add the defined user to the defined group.
In order to restrict a post to a group, you need the following API method:
Groups_Post_Access::create( array( 'post_id' => $post_id, 'group_id' => $group_id ) );
As you can already imagine the $post_id is the ID of your post and $group_id is the group id you wish to restrict the post to.
Perhaps you might also need the following, that helps you find the group id from the group name:
if ( $group = Groups_Group::read_by_name( 'Foobar' ) ) {
$group_id = $group->group_id;
}
Hope it helps.
Cheers