WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have this while loop in my product page with Wordpress e-commerce plugin. It is looping through custom post meta.

<?php if (wpsc_have_custom_meta()) : ?>
    <?php $count = 2; ?>
    <?php while ( wpsc_have_custom_meta() ) : wpsc_the_custom_meta(); ?>
    <?php if (stripos(wpsc_custom_meta_name(),'g:') !== FALSE) continue; ?>
        <a href="#tab<?php echo $count; ?>"><?php echo wpsc_custom_meta_name(); ?></a>
    <?php $count ++; ?>
<?php endwhile; ?>
<?php endif; ?>    

I repeat this twice. Once to iterate through tab titles and once through the tab body. But for some reason the second instance of the while loop won't work. If I delete the first instance then the second one works as expected but as soon as I have to examples of it then it no longer works. Thanks for the help.

share|improve this question

closed as off-topic by Pieter Goosen, Johannes Pille, s_ha_dum Oct 11 '14 at 18:22

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

I have to assume the problem is with how those wpsc_* functions work. My guess is that they are looping over an array/object and not resetting at the end. As those are not core functions, though, this is going to be off-topic as being dependent upon third-party code. – s_ha_dum Oct 11 '14 at 18:22
up vote 0 down vote accepted

It doesn't appear possible to loop over the values multiple times without directly manipulating the current_custom_meta class var so that wpsc_have_custom_meta() will return true again. Give this a try before the second while loop:

global $wpsc_custom_meta;
$wpsc_custom_meta->current_custom_meta = -1;
share|improve this answer
You are a wizard. Thanks! – motleydev Feb 12 '13 at 17:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.