Support

Account

Home Forums General Issues Multiple post objects not working

Helping

Multiple post objects not working

  • Howdy!

    I have two post objects on the same code. First I tried to do it with setup_postdata() and reset function but looking here I find out that the better way to do it is calling the necessary fields with $post->ID parameter since I’m already calling the main post into a modal with setup_postdata(). Unfortunately both setup_postdata() and secondary parameter only calls the first custom field needed. I’m using on ACF fields config both as bidirectional post relation to get more than one post in a array. Here’s my code:

    $posts = get_field('post_relacionado1');
    if( $posts ):
    echo '<ul id="related1">';
    foreach( $posts as $post):
    echo '<a href="' . echo get_permalink($post->ID); . '">';
    echo '<li>' . echo get_the_title($post->ID); . '</li>';
    echo '</a>';
    endforeach;
    echo '</ul>';
    endif;

    $posts2 = get_field('post_relacionado2');
    if( $posts2 ):
    echo '<ul id="related2">';
    foreach( $posts2 as $post):
    echo '<a href="' . echo get_permalink($post->ID); . '"><li>';
    echo get_the_title($post->ID);
    echo '<br>'
    echo get_the_content($post->ID);
    echo '</li></a>';
    echo '<a href="' . echo get_permalink($post->ID); . '"><li>';
    echo get_the_post_thumbnail($post->ID);
    echo '</li></a>';
    endforeach;
    echo '</ul>';
    endif;

    If someone have some bright idea I would really appreciate! Thnx!

  • Hi @ianco,

    Thanks for the post.

    Is it possible that you have filtered both fields with the same criteria ie by the same post type or category and that is why they are returning the same results?

    Did you try to filter by different post types?

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Multiple post objects not working’ is closed to new replies.