Skip Navigation

[Closed] Mirror / Sync fields between users and their profiles (CPT)

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.

This topic contains 3 replies, has 2 voices.

Last updated by Christian Cox 9 months, 1 week ago.

Assigned support staff: Christian Cox.

Author
Posts
#1371525

Hi there

We created a membership page with users that can create their own profile. Their profile is a CPT connected to the user (as author). Now we would like to allow users to search for other users.

For the most part, we can follow this tutorial: https://toolset.com/documentation/post-relationships/how-to-create-custom-searches-and-relationships-for-users/

There is just one issue. Some important fields are stored in the user fields. And those information need to stay there as they are needed for administrative purposes and to sync user data to MailChimp.

How can we make the user meta available for search? The only option I see currently, is to sync / mirror fields between users and their profile.

For example the user firstname is copied to a newly created custom field in the profile CPT (e. g. profile_first_name). And each time someone changes his or her first name, it's again copied to the CPT. That way we could build the search feature as described in the tutorial.

My first question: Is there another way to search for user / profiles without having to sync the fields?

Second question: IF we have to sync / mirror the fields, how would we approach that? I assume this isn't possible out of the box, but I thought it wouldn't hurt to ask.

Thanks a lot for your help!

Best,
Marcial

#1371549

Christian Cox
Supporter

Languages: English (English )

Timezone: America/New_York (GMT-04:00)

My first question: Is there another way to search for user / profiles without having to sync the fields?
Not really, if you want to include those custom fields to be used as search filter criteria. The values must be copied into the custom post type's custom fields, and the search filters must be created from the custom post type fields.

Second question: IF we have to sync / mirror the fields, how would we approach that? I assume this isn't possible out of the box, but I thought it wouldn't hurt to ask.
It would most likely require custom code. Let's assume the Form used to create the CPT is submitted by the User. If that is the case, then you can use the cred_save_data hook to trigger custom code when the Form is submitted. First you would set up the corresponding custom fields in the custom post type. Then when the Form is submitted, the custom code can look at the User's profile (based on the current User) for all the information you want to store in the custom post, and save that information in the corresponding post custom fields. We have information about the cred_save_data hook available here: https://toolset.com/documentation/programmer-reference/cred-api/

You can use the get_user_meta function and the update_post_meta function to get and set the data from the User's profile in the custom post.
https://developer.wordpress.org/reference/functions/get_user_meta/
https://codex.wordpress.org/Function_Reference/update_post_meta

Note that Types custom fields use the 'wpcf-' prefix in the database, so you must use the wpcf- prefix with get_user_meta or update_post_meta.

Let me know if you have questions about implementing the cred_save_data API, and I can offer some guidance.

#1375575

Hi Christian

Thank you so much for your help. It looks as if we can do the implementation on our own from here on out. Should we still have any questions, I'll get back to you.

Best,
Marcial

#1375599

Christian Cox
Supporter

Languages: English (English )

Timezone: America/New_York (GMT-04:00)

That sounds great, I'll stand by for your update.

The topic ‘[Closed] Mirror / Sync fields between users and their profiles (CPT)’ is closed to new replies.