简体   繁体   English

WordPress ACF Relation字段循环显示页面

[英]WordPress ACF Relation field loop out pages

I have created a Relation field to create a little menu with a few links in it. 我创建了一个“关系”字段,以创建一个带有一些链接的小菜单。 I've selected my pages and wrote the loop with the help of the documentation provided on the ACF website. 我已经选择了页面,并借助ACF网站上提供的文档编写了循环。 The problem is the loop doesn't seem to be working. 问题是循环似乎不起作用。 I get no errors and there's nothing to see, when I try to debug and dump the variable that is supposed to get the data it says NULL. 当我尝试调试并转储应该获取数据的变量为NULL时,没有错误,也看不到任何东西。

Anyone knows what is going wrong here? 有人知道这里出了什么问题吗? Been trying to fix it for multiple days now :/ 一直在尝试修复它很多天:/

Here's my loop: 这是我的循环:

<?php 

    $posts = get_field('field_56ebc552c03cb');

    if( $posts ): ?>
        <ul>
        <?php foreach( $posts as $p ): ?>
            <li>
                <a href="<?php echo get_permalink( $p->ID ); ?>"><?php echo get_the_title( $p->ID ); ?></a>
            </li>
        <?php endforeach; ?>
        </ul>
    <?php endif; ?>

I' ve found the issue, since I am using a field in my custom options page to retrieve the data I should use this: 我已经找到了问题,因为我在自定义选项页面中使用字段来检索数据,因此我应该使用此字段:

$menu_posts = get_field('footer_links', 'option'); $ menu_posts = get_field('footer_links','option');

And my loop should look like this: 我的循环应如下所示:

<?php 

    $menu_posts = get_field('footer_links', 'option');

    if( $menu_posts ): ?>
        <ul>
        <?php foreach( $menu_posts as $p ): ?>
            <li>
                <a href="<?php echo get_permalink( $p ); ?>"><?php echo get_the_title( $p ); ?></a>
            </li>
        <?php endforeach; ?>
        </ul>
    <?php endif; ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM