0
votes

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. 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.

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; ?>
1
Try to rename variable $posts to $menu_posts - htmlbrewery
Doesn't work unfortunately, still gives NULL when I try to dump it - Frank Lucas
I think the problem comes from this function get_field('field_56ebc552c03cb'),incorrect parameters or incorrect post ID, check again parameters - htmlbrewery
The field ID is correct - Frank Lucas
Thats wrong, please view this article link, function get_field($field_name, $post_id, $format_value); first parameter is $field_name not field ID - htmlbrewery

1 Answers

0
votes

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');

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; ?>