- You should see "static content test, followed by usermeta: " at the beginning of the post content.
Correct, that is what I see. I do not see the metadata.
Please go to wp-admin > Users > Your Profile and show me a screenshot of the staff-role User field. What value is selected for your User? You can see mine in user-profile.png - I have "Option title 2" selected.
Using Types, field type select, with exactly the same data of the tutorial.
The tutorial doesn't include any information about the options and values in the select field, so please provide more information about the select field and its options. Something like your screenshot CleanShot 2020-04-20 at 01.57.15@2x.png, but please show the information for the Staff role select field instead. You can see mine in edit-field.png
- the author whose author archive is currently being displayed,
I don't understand this part.
Sorry for the confusion, let me try to explain. An author archive is an archive of the posts created by one User. For example, hidden link will hold an archive of posts created by User joe-smith. I was asking if you want show the staff-role custom field for joe-smith in the author archive for joe-smith.
I expect to see the user custom data staff-role, which is a single line (I am expecting to see the description and the placeholder). If you could expand on this.
Staff role is a select field, not a single line. I think this was just an oversight, though, no problem.
If I understand correctly I have to create the field in HTML on the frontend (in this case a single line and a checkbox).
I then have to send a POST request on ajax_admin to retrieve the content of the metadata back on the frontend.
I'm not really sure what all this is for. There is no need for a POST request to display a User field on the front-end. There's no need to create a field in HTML on the front-end. In your PHP template you can simply echo types_render_usermeta, and the selected option should be displayed. In single-cpt.php, for example:
// ... get_header and other stuff before this
echo '<h2>this is my single-book.php template</h2>';
echo types_render_usermeta('user-select-1');
echo '<br />this is after usermeta';
I also added in my Toolset Content Template for Books just before wpv-items-found:
<h2>This is in my Toolset-based content template applied to single Book posts</h2>
User select 1: [types usermeta='user-select-1'][/types]<br />
The result can be seen in attached single-book.png. You can see the selected option text "Option title 2" is displayed by types_render_usermeta and also by the Types field shortcode.
I also have tried this code:
$toolset1 = get_post_meta(get_the_ID(), 'wpcf-this', true);
echo '</br>and again with userfield: '.types_render_field( 'this').'</br>and this: '.$toolset1;
The function get_post_meta is for getting custom field values from a post of some kind, not from a User profile. You cannot access User fields with get_post_meta. You must use a different function, like get_user_meta: https://developer.wordpress.org/reference/functions/get_user_meta/
The types_render_usermeta function is similar to get_user_meta, but it applies additional formatting based on the options you provide in the arguments array. If you use get_user_meta to get this User field, the result will be 2, not Option title 2. If you use types_render_usermeta, you can get Option title 2. I hope this helps clarify.