0

I need to get user meta from the database and WordPress has the awesome function get_user_meta() for this purpose but, the problem is I need not default meta field. I need to get data from a custom field created with ACF-pro. And I really confused about how to do this. I try:

$user_data = get_user_meta('19') 
print_r($user_data)

And among a large number of different data, I see what I need:

[user-sector] => Array ( [0] => a:3:{i:0;s:3:"602";i:1;s:3:"601";i:2;s:3:"584";} ) [_user-sector] => Array ( [0] => field_611d13578192e ) [user-country] => Array ( [0] => a:1:{i:0;s:2:"17";} ) [_user-country] => Array ( [0] => field_611d138e8192f ) )

Of course I tried using: get_user_meta('19', 'user-country') and also I tried using: get_user_meta('19', '_user-country') and of couse nothing as a result. The result is just an empty array. So is there really a method to get data from meta fields created with acf?

3
  • Have you looked at the ACF docs? advancedcustomfields.com/resources/… Sep 14, 2021 at 12:25
  • Sorry, I forgot to write about it, yes of course I checked "Get values from a user" out in the ACF docs. And try to implement the recommendation with the same result = nothing( Sep 14, 2021 at 12:30
  • 1
    Have you tried get_user_meta('19', 'user-country', true)? Sep 14, 2021 at 12:46

1 Answer 1

0

Here's what I use:

<?php global $current_user; wp_get_current_user(); ?>
<?php if ( is_user_logged_in() ) { 
echo 'User ID: ' . $current_user->ID . "<br>"; 
?>
<a href="<?php echo $current_user->favorite_url;?>">View</a> <?php
 } 
else { wp_loginout(); } ?>

You can just use the ID you have and change $current_user->ID to $current_user->user-country

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.