Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi snails07, did you find a solution yet?
    Having the same needs.

    Kind regards

    Fixed!

    – Add the code below to the functions.php file.
    – Create a User object taxonomy. (eq. ‘Professions’)
    (with help from: justintadlock.com)
    – Now map the User Meta in the User Registation Add-on:
    ‘Professions’ -> (Drop Down field – populated by a taxonomy)
    – The new function will now loops through all User meta. If a User meta keyname corresponse with a taxonomy name, the values are mapped.

    Ps. this solution does not support multi term selection (yet)

    Good luck!

    // Hook Gravity Forms user registration -> Map taxomomy
    
    	function map_taxonomy($user_id, $config, $entry, $user_pass) {
    
    		global $wpdb;
    
    	// Get all taxonomies
    		$taxs = get_taxonomies();
    
    	// Get all user meta
    		$all_meta_for_user = get_user_meta($user_id);
    
    	// Loop through meta data and map to taxonomies with same name as user meta key
    		foreach ($all_meta_for_user as $taxonomy => $value ) {
    
    			if (in_array ($taxonomy, $taxs) ) {			// Check if there is a Taxonomy with the same name as the Custom user meta key
    
    			// Get term id
    				$term_id = get_user_meta($user_id, $taxonomy, true);
    				If (is_numeric($term_id)) {				// Check if Custom user meta is an ID
    
    					Echo $taxonomy.'='.$term_id.'<br>';
    
    				// Add user to taxomomy term
    					$term = get_term( $term_id, $taxonomy );
    					$termslug = $term->slug;
    					wp_set_object_terms( $user_id, array( $termslug ), $taxonomy, false);
    
    				}
    			}
    		}
    
    	}
    	add_action("gform_user_registered", "map_taxonomy", 10, 4);

    Small correction:
    – remove the ‘Echo’ command from the Foreach loop. =)

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: Gravity Forms Custom Post Types] Custom user taxonomies’ is closed to new replies.