首页 > 解决方案 > 查找链接到自定义帖子类型的唯一自定义字段值

问题描述

我正在尝试列出链接到自定义帖子类型的所有作者(这是一个重复字段)的名称 - 出版物但是我无法获得作者列表。添加后的每个出版物都有一个重复字段“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;

 }

标签: repeatercustom-post-typeadvanced-custom-fields

解决方案


推荐阅读