Skip Navigation

[Resolved] How to show user dropdown list based on emails stored in custom post field?

This thread is resolved. Here is a description of the problem and solution.

Problem:

The user asked how to add a custom select field in a form for the intermediary post edit form, that gets values from the child post's custom fields.

Solution:

Suggested to register a custom shortcode that can be used to populate the options for a generic field in the form.

Relevant Documentation:

https://toolset.com/documentation/customizing-sites-using-php/functions/#email

https://developer.wordpress.org/reference/functions/get_posts/

https://developer.wordpress.org/reference/classes/wp_query/#author-parameters

This support ticket is created 2 years, 5 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: Asia/Karachi (GMT+05:00)

Author
Posts
#2222781

Scenario:
Parent post - Project Prompt
Child Post - Group
Relationship - M2M
Intermediate Post - Workspace

A group can have multiple members and these members are assigned to the group by adding their email addresses to a multiple value custom field. This list of emails is then stored in a custom field on the workspace post.

A workspace is meant to be a place where members get together and work on a group project. One step in the group project is the evaluation of every teammate.

I am using generic fields to create an evaluation rubric and then storing that data as a JSON in the workspace custom field. The JSON/ array will look like this -
[Evaluater1 Email] [evaluatee1 email] [rubric-element-1] [rating]
[Evaluater1 Email] [evaluatee1 email] [rubric-element-2] [rating]
[Evaluater1 Email] [evaluatee1 email] [rubric-element-3] [rating]

[Evaluater1 Email] [evaluatee2 email] [rubric-element-1] [rating]
[Evaluater1 Email] [evaluatee2 email] [rubric-element-2] [rating]
[Evaluater1 Email] [evaluatee2 email] [rubric-element-3] [rating]

.....

[Evaluater4 Email] [evaluatee3 email] [rubric-element-1] [rating]
[Evaluater4 Email] [evaluatee3 email] [rubric-element-2] [rating]
[Evaluater4 Email] [evaluatee3 email] [rubric-element-3] [rating]

To store the data as above, I need to show the list of evaluatees in the edit workspace form so that
1. Evaluator can select 1 evalutee at a time and then rate using the rubric
2. The list of evaluatees keep on decreasing with each evaluation.... something like 2/3 complete .... 3/3 complete.

I am struggling to find a way to show the user list as a dropdown on the edit workspace form. I tried to use a view but could not find a way to filter
1. Users based on emails listed in the custom field on workspace post
2. Filter user-profile posts (proxy for users ... only one per user) where the author email is one of the emails listed in the custom field on workspace post

I don't want to create an evaluation post type just to capture a one-time evaluation and would rather have all the data stored in the workpace post as a JSON. Another reason to not do this is - I would need to create a relationship between workspace and evaluation but as workspace is an intermediary post so it seems like that cannot happen.

#2223003

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

> A group can have multiple members and these members are assigned to the group by adding their email addresses to a multiple value custom field. This list of emails is then stored in a custom field on the workspace post.

- I see a big challenge in this approach. The original source of member information is the group post where the emails addresses are stored. If you're copying those emails to a custom field in workspace post too, you'll have to keep special care to keep those emails in-sync across the group post and the workspace post, because if a member is later removed from the group, his/her email will need to be removed from the group's post. But the related workspace post will still have that member email in its custom field.

To avoid this, I wouldn't store the email addresses again in the workspace post and would call them from the original source, i.e. custom field from the related group post, whenever needed.

> 1. Users based on emails listed in the custom field on workspace post
- If you know the ID of the current workspace post, you can get the emails from the custom field using the Type Fields API:
https://toolset.com/documentation/customizing-sites-using-php/functions/#email

You'll add a generic field and populate its options using a custom shortcode, that will return the options based on the emails coming from the custom field.

> 2. Filter user-profile posts (proxy for users ... only one per user) where the author email is one of the emails listed in the custom field on workspace post
- Again, this will need a custom shortcode, that can first get the user IDs from the found emails. Once you have the IDs, you can use the 'get_posts' function to return only those user-profile posts, where the post author is one of the found IDs:

https://developer.wordpress.org/reference/functions/get_posts/
https://developer.wordpress.org/reference/classes/wp_query/#author-parameters

regards,
Waqar

#2223649

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.