Arrays not working on a WP-Ecommerce product page

I am using WP-ecommerce to build a shop, and have a random product generator on the left and right sidebar. So the same product doesnt appear twice on the page, I have got the post id’s from each product in the left sidebar, and excluded them from the product query in the right sidebar.

I am doing this using an array with array_push:

Read More
<?php $leftids = array(); ?>

<?php query_posts('post_type=wpsc-product&showposts=2&orderby=rand&wpsc_rand=i-want-this-product-to-be-random'); if (have_posts()) : while (have_posts()) : the_post(); ?>

<div style="display:none"><?php the_title(); ?></div>

<a href="<?php the_permalink();?>"><?php the_post_thumbnail('sidebarimg');?></a>

<h2><?php the_title(); ?></h2>

<?php  array_push($leftids, $post->ID); ?>
<?php echo $leftids[0]; ?>
<?php endwhile; endif; ?>
<?php wp_reset_query(); ?> 

The problem is I cant access this array when on a product page at all. It works fine on a normal wordpress page such as home or contact us.

Any ideas?

Thanks

Related posts

Leave a Reply

1 comment

  1. not sure where the code snippet is placed, and where you are trying to access it from. A simple (but ugly) solution might simply be to set this array to be global.

    Something like

    $GLOBALS['leftids'] = $leftids;
    

    and then from the other code use

    global $leftids;
    echo $leftids[0];