I'm trying to run two loops on a page. After the first loop runs, it completely stops the second loop. I looked into it and read up on wp_reset_postdata() and wp_reset_query(), neither of which have helped me so far.
My first loop looks like this:
<?php
$args = array(
'post_type' => 'agents'
);
$posts = new WP_Query($args);
if( $posts->have_posts() ): while( $posts->have_posts() ) : $posts->the_post(); ?>
<wordpress post here>
<?php
endwhile;
wp_reset_postdata();
endif;
?>
A little ways down the page, we get the loop that isn't working due to the first loop:
$args = array(
'post_type' => 'properties',
'posts_per_page' => -1,
'property_types' => $page,
'property_cities' => $urlCity,
'meta_key' => 'select-agent-value',
'meta_value' => $agentId,
's' => $urlAddress
);
$posts = new WP_Query($args);
if( $posts->have_posts() ): while( $posts->have_posts() ) : $posts->the_post();
<wordpress post here>
endwhile;
wp_reset_postdata();
endif;
The arguments in the second loop are from this code that runs a little before it:
$page = $_GET['property-type'];
$urlCity = $_GET['city'];
$urlAddress = $_GET['address'];
$agentId = $_GET['agentId'];
if ($page == 'all') {
$page = '';
}
if ($urlCity == 'all') {
$urlCity = '';
}
if ($agentId == 'all') {
$agentId = '';
}
I get the feeling it could something simple I'm missing. Appreciate any help anyone can give!