Reputation: 172
I know this is duplicated to this one How to display an acf field from a user profile?
I copied the code but it is not working, I tried googling and tried also the code here
https://www.advancedcustomfields.com/resources/how-to-get-values-from-a-user/ and it is not also working
This is my code:
<?php
acf_form_head();
get_header();
$author_id = get_the_author_meta('ID');
$author_field = get_field('author_content', 'user_'. $author_id );
?>
<?php echo $author_field; ?>
User Kristen - should display 'Kristen Content'
User Admin - should display 'Admin Content'
User Testa - should display 'Testa Content'
It is just displaying the Admin Content when i tried to logged in user kristen and user testa it should display their own content. I don't know what is wrong with my code.
Upvotes: 0
Views: 4728
Reputation: 1
I was having an issue with this before and here's the solution:
Change
$author_id = get_the_author_meta('ID');
$author_field = get_field('author_content', 'user_'. $author_id );
To
$author_id = get_current_user_id();
$author_field = get_field('author_content','user_'. $author_id);
This will solve it.
Upvotes: 0
Reputation: 172
solved it
<?php $user_data = get_user_meta(get_current_user_id());
echo $user_data['author_content'][0]; ?>
Upvotes: 1