- This topic has 1 reply, 2 voices, and was last updated 13 years, 11 months ago by .
Viewing 2 posts - 1 through 2 (of 2 total)
Viewing 2 posts - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.
Support site for Tips and Tricks HQ premium products
by
Tips and Tricks HQ Support Portal › Forums › WP eStore Forum › WP eStore Troubleshooting › Custom fields within PHP shortcodes
Tagged: custom fields, custom post, custom post type, shortcode
I’ve successfully inserted the PHP shortcode into my custom post template:
<?php echo eStore_show_download_now_button(1); ?>
However I want to replace the Product ID with a value from a custom field (“product-id”), so the store product custom post editor can just allow the user to enter the product ID number, and then the shortcode is automatically generated for that specific product ID.
HOw would I modify the above PHP code to achieve this?
You just pass in the parameter value of the custom field “product-id” in the function.
So first retrieve your custom field value and store it in a variable then pass that variable into the function. Here is an example code (not sure if it will work for your situation but this is how its done):
<?php
$product_id = get_post_meta($post->ID, 'product-id', true);
echo eStore_show_download_now_button($product_id);
?>
Here is another related post:
https://support.tipsandtricks-hq.com/forums/topic/call-product-through-a-custom-field