Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

Thanks.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

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.

share|improve this answer
add comment

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');
share|improve this answer
    
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 at 17:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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