Skip Navigation

[Resolved] Copying fields to/from user profile and CPT

This support ticket is created 3 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 1 reply, has 2 voices.

Last updated by Jamal 3 years, 3 months ago.

Assisted by: Jamal.

Author
Posts
#2117417
Screenshot_20210717_084955.png
Screenshot_20210717_084933.png
Screenshot_20210717_083836.png
Screenshot_20210717_083518.png

I am creating a site that includes player profiles. These are setup as CPTs so they can be displayed like posts. But the data entry is done by the player, not by the site owner. So each player has an account on the site, too.

A player profile includes personal information such as height, weight, sports played, positions, graduating year, and so forth as seen on the screen shots. Two related post types are used: School (the player's high school, a many players to one school relationship) and University (the universities the player is considering, a many-to-many relationship between Universities and players)

To see how the information is laid out and the relationships, check the third and fourth screen shots for the edit view. I do not have the front end view complete yet.

I am using a CRED form to do the front-end data entry. The user is directed to the page for the profile entry form immediately after signup. Right now the CRED form is requiring the player to re-enter their name and email address.

I need to do the following.
(first screenshot)
* Under the "Create Profile" page title, I want to show the user First/Last name, as entered in the site user profile.
* I want the First, Last and Email fields populated from the site User Profile, not re-entered.

(second screenshot)
* after the player has uploaded a photo, I want the generated thumbnail put in the site user's profile image field.
* the generated medium image needs to be assigned as the post featured image.
* when the player submits the CRED form, I want the post to get its title from [user first] [user last] [high school] rather than the CRED-generated random post name.

[high school] is a select control populated by another CPT named high school. The relevant info is the post title of the schools CPT.

What are the custom functions I'll need to add to do what's listed?

Alternatively, if there's a way to do this in the User Profile instead of having a Player CPT, I'm sure that would be better in the long run. But I would need to have the ability to use the School CPT to populate a select control, and to have a many-to-many relationship between a User and a University post type.

Thanks for your assistance!

#2117947

Hello and thank you for contacting Toolset support.

Let me start with your latest question "Alternatively, if there's a way to do this in the User Profile instead of having a Player CPT, I'm sure that would be better in the long run. But I would need to have the ability to use the School CPT to populate a select control, and to have a many-to-many relationship between a User and a University post type."

That actually won't happen anytime soon, because of how WordPress handles the data. Basically, the backbone of WordPress data is the posts, which are stored in the {wp_}posts table. The posts are created by users and can be classified/categorized by taxonomies. Then you can extend their data with custom fields. Toolset offers relationships, only between posts. So, if you need to have relationships between your data models, you must create them as posts. Maybe you will find this article interesting https://toolset.com/course-lesson/how-to-create-custom-searches-and-relationships-for-users/

This being said, let me answer your question What are the custom functions I'll need to add to do what's listed?
You will most probably need to hook into the Toolset forms actions, especially, the cred_save_data.
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

The action is triggered after a form(user form or post form) is submitted and its data is saved. This way, you can directly create the Player Profile, and add the first name, last name, and email to it. Then, you can redirect the user to an edit form of his own Player Profile post. Check an example here https://toolset.com/forums/topic/have-a-band-admin-role-to-manage-cpt-band-listing-page/

Regarding the featured image, you will need to use the set_post_thumbnail funtion.
https://developer.wordpress.org/reference/functions/set_post_thumbnail/

However, for the user's profile image, it is a bit different, because WordPress does not offer that out of the box. By default, WordPress only supports user profile images from the Gravatar service hidden link
To use uploaded images, you will need a 3rd party plugin or custom code. For example https://wordpress.org/plugins/wp-user-avatar/

I am aware that my reply does not include all the details you may be looking for. But, it tries to give some guidance on how to achieve your requirements. Let me know what or where you need more details and I'll do my best to help.