【发布时间】:2014-01-26 10:13:22
【问题描述】:
我想创建一个包含所有用户配置文件的页面,但我只想显示他们在其用户配置文件的高级自定义字段中定义的图像。
我试图做这样的事情:
<?php if (is_page(9)){ ?>
<section class="pageContent contentWidth">
<ul class="profilePictures">
<?php
$blogusers = get_users('orderby=nicename&role=subscriber');
foreach ($blogusers as $user) {
echo '<li><div class="image_wrapper"><img class="profile1" src="';
$user->the_field('profilbild');
echo '"/></div><img class="profile2 hoverShow" src="';
$user->the_field('funbild');
echo '"/><div class="imageOverlay"><p>';
$user->the_field('nickname');
echo '</p></div></li>';
}
?>
</ul>
</section>
<?php } ?>
但我在前端得到的只是:
<section class="pageContent contentWidth">
<ul class="profilePictures">
<li><div class="image_wrapper"><img class="profile1" src="
然后就结束了。
编辑:错误是:
致命错误:调用未定义的方法 WP_User::the_field() in .../index.php 第 208 行
这是一行
$user->the_field('profilbild');
所以我似乎无法从那里调用此方法。 但是那我该怎么办呢?
编辑2: 所以我找到了方法未找到错误的解决方案。我现在只是回显这些字段的简码:
echo '<li><div class="image_wrapper"><img class="profile1" src="
[acf field="profilbild"]
"/></div><img class="profile2 hoverShow" src="
[acf field="funbild"]
"/><div class="imageOverlay"><p>
[acf field="nickname"]
</p></div></li>';
但它无法找到我认为的正确用户。 ACF 不知道该去找哪个用户。
对此有什么解决方案?
【问题讨论】:
-
在你的 wp-config.php 文件中设置 wp_debug = true 然后检查是什么停止了你的代码。
-
我这样做并用结果编辑了我的问题。
-
var_dump($user);在 foreach 之前输出什么?
-
在 foreach 之前为 NULL,之后它按预期转储用户对象。我认为问题可能是,acf 插件不知道用户要去哪里。
-
我的意思是 var_dump($blogusers);只是为了检查它不为空,
标签: php wordpress frontend advanced-custom-fields