Problem with multiple wp_query loops
-
I have a page where I generate a table sorted based on country. I did this by using customfields and one wp_query pr country. I have a navigation sidebar on the left side. When the sidebar i active the table is generated with a lot of post that should not be there. The first country works fine and that is the only country for now that has any entries. But the other countries gets entries that does not have the same meta_key. I suspect that it gets all posts with the same meta_value regardles of the key. But when i remove the sidebar from the templatepage all the table queries works perfect.
I have tried to add wp_reset_query(); but it did not make any difference.
I have another question to. It does not seem to make any difference if i add ‘cat’ parameters to the query. The search seems to ignore the cat parameter regardless of what i put there.
Here is the wp_query args. All look the same just a different country.
The cat here does not make any difference if I add it or not.$args1 = array( 'cat' => '50', 'showposts' => 1000, 'orderby' => title, 'meta_key' => treningsland, 'meta_value' => $text02, /*Sverige*/ 'order' => asc, );
Here is the code of one of the country entries. All look the same.
<?php $my_posts = new WP_Query(); $my_posts->query($args1); ?> <?php if ($my_posts->have_posts()) { ?> <div class="alignleft"> <h2 class="header_course_table"><?php echo $text02 ?></h2> <table class="course_table"> <tr> <th></th> <?php if (get_post_meta($post->ID, 'kursdatum', true)) { ?> <th><?php echo $text13; ?></th> <th><?php echo $text10; ?></th> <th><?php echo $text11; ?></th> <?php } else { ?> <th><?php echo $text09; ?></th> <th><?php echo $text10; ?></th> <th><?php echo $text11; ?></th> <th><?php echo $text12; ?></th> </tr> <?php } ?> <?php while ($my_posts->have_posts()) : $my_posts->the_post(); ?> <tr class="<?=($c++%2==1) ? 'odd' : 'even' ?>"> <td> <h3 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php echo $text06; ?><?php the_title_attribute(); ?>"><?php echo $text05 ?></a></h3> </td> <?php if (get_post_meta($post->ID, 'kursdatum', true)) { ?> <td> <?php echo get_post_meta($post->ID, 'kursdatum', true); ?> </td> <td> <?php echo get_post_meta($post->ID, 'Tid', true); ?> </td> <td> <?php echo get_post_meta($post->ID, 'kursort', true); ?> <?php } else { ?> <td> <?php echo get_post_meta($post->ID, 'Veckodag', true); ?> </td> <td> <?php echo get_post_meta($post->ID, 'Tid', true); ?> </td> <td> <?php echo get_post_meta($post->ID, 'kursort', true); ?> </td> <td> <?php echo get_post_meta($post->ID, 'kurstyp', true); ?> </td> <?php } ?> <?php endwhile; wp_reset_query(); ?> </table> </div> <?php } ?>
- The topic ‘Problem with multiple wp_query loops’ is closed to new replies.