Hello,
when I call the function types_render_usermeta_field("auszubildende-r-zum-zur", array('show_name' => 'true','user_id' => $user->user_id)) from another plugin like author-avatars I receive an error message: PHP Fatal error: Call to undefined function types_render_field_single() in ... on line 681. The message comes only when I click the save button for a page in wp backend. On this page I have a shortcode which loads the plugin for the frontend -> [authoravatars avatar_size=35 show_name=true show_biography=true]
http://wordpress.org/plugins/author-avatars/
My question is, how can I make a call to a custom user field in other plugin.
When I try the solutions from this post -> https://toolset.com/forums/topic/user-fields-select-option-display-text/ I receive the above described error and the result is not the same as in a theme file. As a result I receive only the firs option value of the select box.
When I try this one
"auszubildende-r-zum-zur", array('show_name' => 'true','user_id' => $user->user_id))
I get the value="5" of the selected option, in this case -> 5
Thank you very much,
Ivaylo
Dear Ivaylo,
I suggest you try wordpress function get_user_meta(), for example:
get_user_meta($user->user_id, 'wpcf-auszubildende-r-zum-zur', true);
More help:
get_user_meta
Retrieve a single meta field or all fields of user_meta data for the given user. Uses get_metadata(). This function replaces the deprecated get_usermeta() function.
http://codex.wordpress.org/Function_Reference/get_user_meta
Hi luoy,
sry for the broken code example. It should look like this one:
print_r(types_render_usermeta_field("auszubildende-r-zum-zur", array('show_name' => 'true','user_id' => $user->user_id)));
However, I tried your suggestion:
print_r(get_metadata('user', $user->user_id, 'wpcf-auszubildende-r-zum-zur', true ));
It gave me the following result:
1531111
These are the ids of the possible options in the types select element (see screenshot).
How can I retrive the value of the selected selectbox option, for example: "Luftverke..."
Thank you very much!
Ivaylo
You can call Types function only after Types was loaded in wordpress, you can try Types action hook wpcf_after_init, like this:
add_action('wpcf_after_init', 'call_types_function');
function call_types_function(){
if(function_exists ('types_render_usermeta_field') && !is_admin()){
print_r(types_render_usermeta_field("auszubildende-r-zum-zur", array('show_name' => 'true','user_id' => 1)));
// your custom codes goes here...
}
}
Hi,
I fixed the issue with this one:
if(do_shortcode('[types usermeta="auszubildende-r-zum-zur" user_id="' . $user->user_id . '"] [/types]') != '--- bitte auswählen ---') {
//echo substr_replace(types_render_usermeta_field("auszubildende-r-zum-zur", array('show_name' => 'true')), "", -3);
$biography = do_shortcode('[types usermeta="auszubildende-r-zum-zur" user_id="' . $user->user_id . '"] [/types]');
//echo do_shortcode('[types usermeta="auszubildende-r-zum-zur"] [/types]');
}
Thank you!!!