olliM-3
Support threads created in the last 30 days: 0
Favorite Forum Topics
This user has no favorite topics.
Forum Topics Created
Status | Topic | Supporter | Voices | Posts | Freshness |
---|---|---|---|---|---|
Get related parent post custom field in child post using meta key
Started by: olliM-3 in: Toolset Professional Support |
1 | 2 | 5 years, 6 months ago | ||
Count the sum of numeric custom fields from custom post types
Started by: olliM-3 in: Toolset Professional Support |
2 | 2 | 5 years, 11 months ago | ||
Assign category to new post, based on author user fields
Started by: olliM-3
in: Toolset Professional Support
Problem: I have a Form that allows Users to submit posts. I would like to automatically assign different taxonomy terms to each post based on custom fields in the author's User profile. Solution: Use the cred_save_data hook to add terms to a post created by Forms. Create a custom field on the User profile that can be used in the cred_save_data callback to determine which terms should be added to the post. add_action('cred_save_data', 'set_blog_terms',100,2); function set_blog_terms($post_id, $form_data) { global $current_user; $forms = array( 9544 ); if (in_array($form_data['id'], $forms)) { $array = array( 'malawi-2018' => array('blogi','kapua-2018-malawi'), 'oma-kapua-nepal-2018' => array('blogi','oma-kapua-2018-nepal'), ); $taxonomy = 'category'; $userFieldValue = get_user_meta( $current_user->ID, 'wpcf-kapuaja-hanke', true); if(!$userFieldValue) { return; } $tag = $array[$userFieldValue]; wp_set_object_terms( $post_id, $tag, $taxonomy, true ); } } Relevant Documentation: |
2 | 9 | 6 years, 5 months ago |