Home › Forums › Backend Issues (wp-admin) › Relationship query issues › Reply To: Relationship query issues
Hi @ramon
Please check that your $ids array is correct by debugging it like so:
<?php echo '<pre>';
print_r( $ids );
echo '</pre>';
die; ?>
Looking at your code, it seems to be a jumble of WP_Query
and get_posts
.
Please keep to 1 consistent style like so:
<?php
$ids = get_field('relacionado', false, false);
$the_query = new WP_Query(array(
'post_type' => 'produtos',
'posts_per_page' => 3,
'post__in' => $ids,
'post_status' => 'any',
'orderby' => 'rand',
));
// The Loop
if ( $the_query->have_posts() ):
while ( $the_query->have_posts() ): $the_query->the_post();
?>
<div>
<img src="<?php echo get_field('imagem_chamada'); ?>" alt="">
<h2><a href="<?php the_permalink() ?>" title="" rel="bookmark"><?php the_title() ?></a></h2>
<p><?php echo get_field('chamada'); ?></p>
</div>
<?php
endwhile;
endif;
?>
It is possible that you don’t even need to use a custom WP_Query at all. Have you tried looping over the results from get_field('relacionado')
?
Thanks
E
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.