Skip Navigation

[Resolved] Set post's taxonomy to value of author's user field

This support ticket is created 8 years 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/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by Luo Yang 8 years ago.

Assisted by: Luo Yang.

Author
Posts
#383668
2016-04-12_15h42_48.png
2016-04-12_15h42_08.png
2016-04-12_15h40_13.png
2016-04-12_13h43_26.png

I am trying to:
set default values for a post's taxonomy according to fields in it's author's user profile.

I.e.:
1. User sets the field Country in his profile to "France".
2. Any post the user creates through a CRED form has the tag "France"

My goal in the end is to have parametric filters and views that show posts depending one or more categories.
Some of the categories are hierarchical like Country (i.e. Asia->Thailand; Asia->India; Africa->Egypt) or field of employment (Marketing->online marketing; Marketing->PR;) and I should be able to filter by either the parent term or the child term (i.e. filter by "Asia" or filter by "Thailand")

I don't want to use nested views since I expect those to perform worse and to I expect those to prevent me from nesting further. Nested views would work by first filtering by authors with a certain category and then by showing all of the posts of those authors in a view.

I don't want users to manually set those categories for each post because that would make mistakes very likely and would mean quiet a hassle for them.

---

Generic fields work for me to insert information from user profile fields into post fields but not for inserting them into taxonomy.

[cred_generic_field field='country' type='hidden' class='' urlparam='']
{
"required":0,
"validate_format":0,
"persist":1,
"default":"[types usermeta="usercountry" user_is_author="true"][/types]"
}
[/cred_generic_field]

I have three questions:
1. What is the smartest way to reach my goal? (set default values for a post's taxonomy according to fields in it's author's user profile)
2. Is it better to use taxonomy or just post fields to reach my goal?
3. How can I set post taxonomies by using user profile field contents in CRED (hidden)?
4. If possible how to map multiple entries to multiple taxonomy entries (i.e countries germany, spain, italy in user profile to germany, spain, italy in post taxonomy)

Thank you!

#383700
2016-04-12_17h34_21.png

I have set up an installation with some basic examples for the forms and views I am talking about:
hidden link
hidden link

As you can see on the screenshot (or in the "view-posts" link) there is information in the user profile. But none of that information ends up in the actual post.

Feel free to use and change that installation to as much as you want.

I am looking forward to your reply!

#384934

Dear milan,

Q1) What is the smartest way to reach my goal? (set default values for a post's taxonomy according to fields in it's author's user profile)

I suggest you try with CRED action hook "cred_save_data" to save the value of custom taxonomy value, see our document:
cred_save_data
This hook allows doing a custom action when post data is saved to database.
https://toolset.com/documentation/user-guides/cred-api/#csd

To update the post's taxonomy value:
wp_set_object_terms
elates an object (post, link etc) to a term and taxonomy type (tag, category, etc). Creates the term and taxonomy relationship if it doesn't already exist.
http://codex.wordpress.org/Function_Reference/wp_set_object_terms

Q2) Is it better to use taxonomy or just post fields to reach my goal?
It depends on yourself, in your case I suggest use taxonomy, you will be able to add more terms in the custom taxonomy.

Q3) How can I set post taxonomies by using user profile field contents in CRED (hidden)?
If you use the CRED action hook "cred_save_data", it will not need to put in the CRED form, works in the server side.

Q4) If possible how to map multiple entries to multiple taxonomy entries (i.e countries germany, spain, italy in user profile to germany, spain, italy in post taxonomy)
Yes, it is possible to customize the options of custom user field with Types filter "wpt_field_options", for example this thread:
https://toolset.com/forums/topic/dynamically-populate-select-field/#post-339548

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