-1

I am using ACF as related posts. I have the following code.

<?php $post_objects = get_field('repeater_related_items');
if( $post_objects ): ?>
    <ul>
    <?php foreach( $post_objects as $post): // variable must be called $post (IMPORTANT) ?>
        <?php setup_postdata($post); ?>
        <li>
            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
            <span><?php the_field('repeater_related_items'); ?></span>
        </li>
    <?php endforeach;?>
    </ul>
<?php wp_reset_postdata(); ?>  
<?php endif;?>
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Main Sidebar') ) : endif; ?>

The problem is that when I add this to sidebar other widget doesn't work.

  • You have reset the post data twice. That could cause trouble in some circumstances, but I suspect the problem is in how you add this to the sidebar. Please edit your question to include that code. – s_ha_dum Jan 29 '14 at 15:02
  • I just edited my code including sidebar. – Hussain Ansari Jan 29 '14 at 15:08
  • get_field() is a custom function of ACF, right? The sidebar is outside of the loop, so how would the function know the post for which to get the specified meta data? Also: please clarify "other widget doesn't work": what other Widget, and in what way does it not work? – Chip Bennett Jan 29 '14 at 15:48
  • Sidebar is not a part of code. – Hussain Ansari Jan 29 '14 at 16:33
  • What kind of data is in the $post_objects variable? An array of ID's? – eteich Jan 29 '14 at 21:43
1

I removed the following line and fixed. <span><?php the_field('repeater_related_items'); ?></span>

  • 1
    If possible, can you explain why that might have fixed the issue? – Tom J Nowell Feb 4 '14 at 12:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.