repeater - 查找链接到自定义帖子类型的唯一自定义字段值
问题描述
我正在尝试列出链接到自定义帖子类型的所有作者(这是一个重复字段)的名称 - 出版物但是我无法获得作者列表。添加后的每个出版物都有一个重复字段“linked_author”和子字段“paper_linked_author”,通过该字段链接多个作者。
子字段“paper_linked_author”是一个 post_object,实际上是一个自定义 post_type - people。
最终的唯一作者列表将显示在手风琴中,单击时将显示他们链接到的所有出版物。虽然我还没有处理这个代码......
该列表也没有生成!如果我回显某些内容,则循环工作正常,直到 foreach ( $the_posts as $the_post ) {,但之后没有回显。错在哪里?
这是代码。
$the_posts = get_posts( array(
'posts_per_page' => '-1',
'post_type' => 'publications',
'order' => 'DESC'
));
foreach ( $the_posts as $the_post ) {
if(have_rows('linked_author')) : // linked_author is the Repeater field
while ( have_rows('linked_author') ) : the_row();
$post_object = get_sub_field('paper_linked_author');
echo '<ul>';
if( $post_object ):
$post = $post_object;
setup_postdata( $post );
echo '<li>';
echo '<a href="<?php echo the_permalink();?>"><?php the_title();?></a>';
echo '</li>';
endif;
echo '</ul>';
wp_reset_postdata();
endwhile;
endif;
}
解决方案
推荐阅读
- ionic-framework - 如何在 Ionic 4 中捕获 AlertController 的数据返回?
- hashtable - 具有双重哈希和双素数的哈希表,没有二级哈希函数
- python - 如何将日期时间列表项更改为 datetime.date
- java - Gradle 找不到插件存在于中央插件存储库中
- scala - Foreach 在列表的第一个元素上
- c++ - 如何将 DLL 添加到 C++ 程序(访问 SQL 数据库)
- javascript - 单元测试嵌套异步函数时的异步回调超时
- python - 四倍积分功能给了我一些意想不到的零?
- testing - Testcafe 和 Browserstack - 找不到浏览器
- linux - Windows 和 Linux 安装之间的 Oracle 18 c DATA 差异