【发布时间】:2018-07-11 01:30:51
【问题描述】:
但我仍然无法使用此代码检索任何行
<?php
require_once 'wp-load.php';
require_once ABSPATH . '/wp-admin/includes/taxonomy.php';
include_once 'wp-content/plugins/acf351/acf.php';
// check if the repeater field has rows of data
if( have_rows(get_field('ddw')) ):
// loop through the rows of data
while ( have_rows(get_field('ddw')) ) : the_row();
// display a sub field value
echo the_sub_field('op1');
endwhile;
else :
echo 'no rows found';
endif;
?>
它没有找到 row 。我希望每个帖子的所有行,特别是我希望将 http 链接放在数组上并循环遍历它。我已将此脚本放在 wp 目录中,它不是主题或模板文件夹。请帮助我在哪里做错了。在此先感谢
【问题讨论】:
-
我会使用
echo get_sub_field或the_sub_field而不是echo the_sub_field -
我试过了,但仍然是“找不到行”,这样你就知道我不是在尝试获取一个帖子的元值,我正在尝试获取所有帖子的子字段“op1”行。
-
好吧,我不是专家,但我熟悉 ACF 中继器插件。我还注意到您可能需要删除 'ddw' 上的 get_field... 即 if( have_rows('ddw') ): // 循环遍历数据行 while ( have_rows('ddw') ) : the_row( );
-
git-e-up 是对的,直接把'ddw'放在两个have_rows()中
-
我试过了,但它仍然显示没有找到行。我认为 have_rows 应该显示特定帖子 id 的子字段行,但我试图从所有帖子中显示。
标签: php wordpress foreach advanced-custom-fields