I'm using the shopp e-commerce plugin. In my template file I need to get the id of the product (post). The online docs for shopp list shopp('product', 'id') but irritatingly this prints the id and there appears to be no alternative that simply returns it. Also confusing, when I do $post->ID it returns -42... which is weird.

Can anyone help me return the post id of individual products inside the shopp loop?



It's turns out that you can add return=true to any of the theme template tags:

shopp('product', 'id', 'return=true');

As of writing this, that is not mentioned in the documentation at all. Shopp support was also able to confirm that the $post->ID variable does get over-written in a number of situations, so the strange value I was seeing is not surprising.

  • a shorthand for this command would be shopp('product.get-id'); this works for every shopp() tag. – RST May 26 '15 at 13:49

This also works to get the current product's id:

$product_id = ShoppProduct()->id;

This is equivalent to:

$product_id = shopp('product','id','return=true');
  • It's not clear what you are trying to say with the answer. Please edit the Answer again and add some details with the code so that someone understand easily. – Mayeenul Islam Jan 2 '14 at 17:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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