ACF 灵活内容 - 从作者页面获取数据时不显示任何内容

ACF Flexible Content - Not showing anything when taking the data from author page

内容不想显示。我已经多次阅读并浏览了文档。我什至请其他开发人员查看和检查代码,对他们来说看起来是正确的。

我需要它出现在作者页面上。我已经在自定义 post 类型、页面等上对此进行了测试......并且它有效。但是,此信息必须来自作者页面。

这是我的字段:

此处显示字段:

下面是我的代码。它总是什么都不显示。这是为什么?我有版本 5.6.1

```

// check if the flexible content field has rows of data

if( have_rows('social_media') ):

     // loop through the rows of data
    while ( have_rows('social_media') ) : the_row();

        if( get_row_layout() == 'social_media_icons' ):

         echo   the_sub_field('media_facebook');

        endif;

    endwhile;

else :

    echo "nothing";// no layouts found

endif;

?>

```

试试这个:

$page_id = //your page id;

// check if the flexible content field has rows of data

if( have_rows('social_media',$page_id) ):

 // loop through the rows of data
 while ( have_rows('social_media',$page_id) ) : the_row($page_id);

    if( get_row_layout() == 'social_media_icons' ):

     echo   the_sub_field('media_facebook');

    endif;

 endwhile;

else :

echo "nothing";// no layouts found

endif;

?>

从该行删除回显 the_sub_field('media_facebook');

    // check if the flexible content field has rows of data
    if( have_rows('social_media') ):

         // loop through the rows of data
        while ( have_rows('social_media') ) : the_row();

            if( get_row_layout() == 'social_media_icons' ):

                the_sub_field('media_facebook');

            endif;

        endwhile;

    else :

        echo 'nothing'; // no layouts found

    endif;

我想通了。

这是一个作者页面。作者有很多,每一位都是独一无二的。

如果我们尝试拉取字段,假设有 10 个作者,它将拉取哪个字段?标准循环在这里不起作用。

我们需要传递作者id。 user_1.

现在,那是静态的,我们希望它是动态的,所以我们可以获得作者 ID,然后将其连接到 user_$id。

如:

 $author_id = get_the_author_meta('ID');

  while ( have_posts() ) : the_post();

                if( have_rows('social_media','user_'. $author_id) ):

                    while ( have_rows('social_media', 'user_'. $author_id) ) : the_row();

                        if( get_row_layout() == 'social_media_icons' ): ?>


    <?php endif; ?>
                  <?php  endwhile;

                    else :
                        echo 'no content';
                    endif;


                endwhile; // End of the loop.

这会起作用,因为 ID 现在是动态的,我们正在获取当前用户 ID,然后将其连接到 'user_'。

从 5.6.5 版开始,那里的代码可以 100% 工作,并且应该也可以继续工作。