How to display an acf field from a user profile?

2019-07-04 01:04发布

I currently have an advanced custom field setup in the user's profile with a field name of author_title. This would display what the user does at the company blog.

acf user field

I currently have the following working but the title only updates for first user and all users get that title instead of being able to use their own.

Updated

<?php $current_user = wp_get_current_user(); ?>  
<h3><?php the_field('author_title', 'user_' . $current_user->ID); ?></h3>

1条回答
祖国的老花朵
2楼-- · 2019-07-04 01:22

Try to get user ID in another way.

Now you get ID for currently logged in user so it shows the same field everywhere. I assume you need show that filed for author posts so:

$author_id = get_the_author_meta('ID');
$author_field = get_field('author_title', 'user_'. $author_id );
查看更多
登录 后发表回答