I'm not sure what I'm doing wrong, but I need some direction in how to set up user profiles. I would like a way for visitors to our site to be able to set up user profiles. The profiles should have the ability to be edited if needed.
So far, I've created a post type called "profiles". I've used Cred to create the form using the "auto generated" option to use the fields in my profiles post type. So far, this looks good, but when I do a trial run and submit some content, it just shows "Auto Draft" and doesn't display my post. I have the Cred setting set to publish, and I have Access set to edit, delete, publish, etc. (author, contributor & guest).
So, why can't I see the post after I submit?
Thank you!
Dear Dawn
For this to work you need each user to have one profile only and use an edit form. To do this you will need to add some custom code that automatically adds one profile for each user, so that it can be edited.
For example, this shortcode will return the profile id to edit, if it doesnt exist it is created:
add_shortcode('wpv-post-profile-id', 'current_profile_id_shortcode');
function current_profile_id_shortcode() {
global $current_user;
$user = get_posts('post_type=profile&meta_key=wpcf-user_id&meta_value=' . $current_user->ID);
if (empty($user)) {
$id = wp_insert_post(array('post_type' => 'profile'));
update_post_meta($id, 'wpcf-user_id', $current_user->ID);
return $id;
} else {
return $user[0]->ID;
}
}
Next place your edit form in a page like this:
[cred-form form="My Profile" post="[wpv-post-profile-id]"]
Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.
Regards,
Caridad
Thank you for the quick reply. Where, exactly, do I add the code?
add_shortcode('wpv-post-profile-id', 'current_profile_id_shortcode');
function current_profile_id_shortcode() {
global $current_user;
$user = get_posts('post_type=profile&meta_key=wpcf-user_id&meta_value=' . $current_user->ID);
if (empty($user)) {
$id = wp_insert_post(array('post_type' => 'profile'));
update_post_meta($id, 'wpcf-user_id', $current_user->ID);
return $id;
} else {
return $user[0]->ID;
}
}
Dear Dawn,
You can put it in functions.php of your theme. At end, before the closing php tag ?>
Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.
Regards,
Caridad