Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Multiple WP_Query returns the same Meta Box values WordPress

  • SOLVED

Hi,

I am running multiple WP_Query loops on one page, each of which calls values from a custom meta box.

The problem is that the meta box values from the first loop are being repeated across all loops.

Here is my code;


<?php $query1 = new WP_Query('pagename=page1'); ?>
<?php while ($query1->have_posts()) : $query1->the_post(); ?>
<?php $do_not_duplicate = $post->ID; ?>


<?php while($custom_metabox6->have_fields('tour'))
{

echo $custom_metabox6->the_value('benefit');

}
?>

<?php endwhile;wp_reset_query(); ?>


<?php $query2 = new WP_Query('pagename=page2'); ?>
<?php while ($query2->have_posts()) : $query2->the_post(); ?>
<?php $do_not_duplicate = $post->ID; ?>


<?php while($custom_metabox6->have_fields('tour'))
{

echo $custom_metabox6->the_value('benefit');

}
?>

<?php endwhile;wp_reset_query(); ?>


Any thoughts?

(I am using the WPAlchemy Meta Box class supplied by: [[LINK href="http://www.farinspace.com/wpalchemy-metabox/"]]Farinspace.com[[/LINK]]

Answers (2)

2011-10-11

Ivaylo Draganov answers:

Hello,

You have to put this in each of the loops (after calling the_post(); ):

// get the meta data for the current post
$custom_metabox6->the_meta();


Wordpressing comments:

Ivaylo to the rescue again!

Thank you :)

2011-10-11

Luis Cordova answers:

try another piece of code for your metabox, a manual one could rule things out