I checked justin tadlocks custom profile field tutorial and wanted to add the field in the custom dashboard widget but it seems it’s not working. I want to show all the user information in this widget.
All that I want to do is add the custom information from the profile field to this dashboard widget and it seems to be not working.
My aim here to to get all author information and show it on this dashboard. Any ideas how to achieve this task?
function example_dashboard_widget_function() {
// Display whatever it is you want to show
the_author_meta();
}
// Create the function use in the action hook
function example_add_dashboard_widgets() {
wp_add_dashboard_widget('example_dashboard_widget', 'User Profile', 'example_dashboard_widget_function');
}
// Hoook into the 'wp_dashboard_setup' action to register our otherfunctions
add_action('wp_dashboard_setup', 'example_add_dashboard_widgets' );
There’s
get_the_author_meta()
for such a task. (get_*
functions normally don’t echo/print the output – hence the name).Normally it’s only meant to be used inside a loop to get the data of the posts author, therefore it internally uses
global $authordata;
.But, you can also throw in the data of the current user, as user data is always the same (same tables, same data).
Now the only thing left is to call the meta for each field, using
get_user_meta()
, which is pretty much equal (for this task) toget_the_author_meta();
.Then just loop through it: