Potentially quick question using do_shortcode()... (2 posts)

  1. bfeely
    Posted 3 years ago #


    I'm not fairly knowledgeable with PHP, but hopefully somebody can help me with a little problem I'm having...

    So, I'm trying to add a shortcode after each post (this is the WP Paypal Shopping cart plugin) [wp_cart:PRODUCT-NAME:price:PRODUCT-PRICE:end].

    I've played around with the <?php do_shortcode(); ?>, which I believe is the right tool to use. So I simply add <?php do_shortcode('[wp_cart:PRODUCT-NAME:price:PRODUCT-PRICE:end]'); ?>.

    In place of PRODUCT-NAME, I want to insert the title of the post/product, <?php the_title(); ?>, and in place of PRODUCT-PRICE, the custom field <?php meta('price'); ?>.

    Putting <?php do_shortcode('[wp_cart:<?php the_title(); ?>:price:<?php meta('price'); ?>:end]'); ?> isn't working, which makes sense I think because I have a <?php inside another <?php. My "simple" question is how to get the values of <?php the_title(); ?> and <?php meta('price'); ?> inside the shortcode to work correctly, if this is possible.

    Sorry for rambling... Any help would be greatly appreciated! :)

  2. Alex
    Posted 3 years ago #

    you should run this shortcode inside a loop, only then you will get title and price of the current post. Also this plugin should have template functions which are much better if you inside your template files

Topic Closed

This topic has been closed to new replies.

About this Topic