$wpdb->get_results()
returns an array on success, so you can’t simply echo $result;
.
Instead, you can use foreach
to loop through the results and display whatever the data that you want to display:
$results = $wpdb->get_results( $q );
foreach ( $results as $row ) {
echo $row->meta_value . '<br />';
}
But I can see that you’re trying to select just one row, so you’d want to use $wpdb->get_row()
and not $wpdb->get_results()
:
$row = $wpdb->get_row( $q );
if ( $row ) {
echo $row->meta_value;
}
But then again — because wp_usermeta
is the default table for WordPress users’ meta, if you just want to retrieve the meta value, then there’s a function you can (and should better) use — get_user_meta()
:
echo get_user_meta( 771, 'nickname', true );