如何显示用户配置文件中的acf字段? [英] How to display an acf field from a user profile?

查看:105
本文介绍了如何显示用户配置文件中的acf字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在用户个人资料中具有一个高级自定义字段设置,其字段名称为 author_title 。这将显示用户在公司博客上所做的事情。

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.

更新

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


推荐答案

尝试以其他方式获取用户ID。

Try to get user ID in another way.

现在您将获得当前登录用户的ID,因此它在所有位置都显示相同的字段。我假设您需要向作者提交该文件,以便:

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

这篇关于如何显示用户配置文件中的acf字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆