Quantcast
Channel: Toolset » All Posts
Viewing all articles
Browse latest Browse all 20145

Reply To: [Assigned] Attaching users to custom posts

$
0
0

Sorry for the delay answer,
I assume your post type gallery is using slug "gallery"
each user has a gallery post, which is already created, and author is that user.

please try this:

add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
// if a specific form
    if ($form_data['id']==123)
    {
        $current_user = wp_get_current_user();
        $current_ID = $current_user->ID;
		$parameters = array('author'=> $current_ID, 'post_type' => 'gallery');
		$posts = get_posts($parameters);
		if($posts)
		{
			$gallery_ID = $posts[0]->ID;
            update_post_meta($post_id, '_wpcf_belongs_gallery_id', $gallery_ID);
		}
    }
}

Please replace 123 with your CRED form post ID.


Viewing all articles
Browse latest Browse all 20145

Trending Articles