Skip Navigation

[Resolved] Automatically fill form field (taxanomy)

This support ticket is created 6 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 2 replies, has 2 voices.

Last updated by olegS-4 6 years, 5 months ago.

Assisted by: Nigel.

Author
Posts
#1095755

Tell us what you are trying to do?
Website users have a custom field "company" (select). When user create a post via custom post form, automatically fill the cred post field "company" (taxonomy) with a value from user's company field.

And after that give access to edit/delete posts only for users with the same companies (post company = user company)

#1096029

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Where you insert a taxonomy field in a post form (with the cred_field shortcode) you cannot pre-set a value, the value attribute is only available on custom fields.

So the only way to automatically set the taxonomy based upon some user field of the person submitting the form is to omit the taxonomy from the form and set it after the form has been submitted, using the Forms API.

So you would use cred_save_data to hook into the submission process, by which time the post has been created, and so you can get the value of the user country field and set the country term on the post accordingly.

See https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
(and https://codex.wordpress.org/Function_Reference/get_user_meta and https://codex.wordpress.org/Function_Reference/wp_set_post_terms; note that you must set the terms by id not slug, so you will need to retrieve the id using term_exists, as described in this last document).

And after that give access to edit/delete posts only for users with the same companies (post company = user company)

It isn't possible to limit access in such a way. However, if your users are creating the posts and so are authors of the post, you can use Access so that users can only edit/delete their own posts.

See https://toolset.com/documentation/user-guides/setting-access-control/

#1097450

Thanks for your reply! I solved the problem by my own. I'm using a js script to assaign the value from user's Company field to post. And Conditional output to control access to edit button and check if user's Company equal post's Company.

Is it possible to use cred_save_data via Toolset's GUI?