How to display an acf field from a user profile?

岁酱吖の 提交于 2019-12-10 19:09:08

问题


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.

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:


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 );


来源:https://stackoverflow.com/questions/38253265/how-to-display-an-acf-field-from-a-user-profile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!