Home › Forums › General Issues › Relationship query from custom post type on external page › Reply To: Relationship query from custom post type on external page
I’ve boiled down your code to the important bits so that it’s easier to see why it’s not working and what to change
<?php
// start of main loop
while (have_posts()) {
// main query is being used
the_post();
$args = array(
// your query args here ...
);
$query = new WP_Query($args);
if ($query->have_posts()) {
while ($query->have_posts()) {
// sub qury is being used
// do some stuff
$query->the_post();
$posts = get_field('performers');
if( $posts ) {
// hold the current post in a temp var
// why below
$temp_var = $post;
foreach( $posts as $post) {
setup_postdata($post);
// do stuff
}
// if we do wp_restet_postdata
// it resets to the main query, not the secondary query
// wp_reset_postdata();
// do this instead
$post = $temp_var;
}
}
// do some more stuff
// this resets to the main query
wp_reset_postdata();
}
} // end main loop
?>
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.