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 am using products as a 'custom post type' then I'm displaying a gallery of all products on the home page with a buy button next to each one. When the buy button is clicked, I would like it to redirect to a page with some more info of that product and a checkout form. What do I need to send to the URL using the button to retrieve this type of page? Should I just write my own query or is there something in wordpress that can do this for me?

This is my form right now:

<form class='product_form' action="checkout" method="get">
<input name="post_id" type="hidden" value="<?=$post->ID?>"/>
<input type='image' src='<?php  bloginfo('template_url'); ?>/images/buy.png' class='wpsc_buy_button' /> 
</form> 
share|improve this question
add comment

2 Answers 2

up vote 0 down vote accepted

If you want to reach the "single" page of a custom post type (or even a regular post), you can do this by going to http://example.com?p=[post_id]&post_type=[post_type_name]. If you use Pretty permalinks WordPress will redirect you to the "canonical" link, which may look like http://example.com/my-post-type/my-post-name/.

So by changing the target of your form and the post_id hidden input to p it should work:

<form class='product_form' action="checkout" method="get" target="<?php home_url(); ?>">
<input name="p" type="hidden" value="<?=$post->ID?>"/>
<input type='image' src='<?php  bloginfo('template_url'); ?>/images/buy.png' class='wpsc_buy_button' /> 
</form>
share|improve this answer
add comment

You should probably loop through using The Loop (use a custom query), and then use the_permalink().

share|improve this answer
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.