Support » Plugin: Amazon Product in a Post Plugin » Shortcode not executing in PHP?

  • Resolved JessycaFrederick

    (@jessycafrederick)


    I want to execute the shortcodes in PHP.

    The code below is correctly retrieving the asins and seems to be correctly writing the shortcodes (when it’s not commented out), but the do_shortcode statement does nothing.

    Is this the best way to execute from PHP? Thanks!

    <?php
    // Retrieve 6 latest posts tagged Books on Solar
    $catPost = get_posts('cat=6&posts_per_page=6');
    foreach ($catPost as $post) : setup_postdata($post);
    	$asin = get_post_meta( get_the_ID(), 'amazon-product-single-asin', true );
    	if ( ! empty( $asin ) )
    	{
    		//echo '[amazon-element asin="'. $asin .'" fields="title,lg-image,large-image-link,button"]';
    		do_shortcode('[amazon-element asin="'. $asin .'" fields="title,lg-image,large-image-link,button"]');
    	}
    endforeach;
    ?>

    https://wordpress.org/plugins/amazon-product-in-a-post-plugin/

Viewing 1 replies (of 1 total)
  • Nevermind. I wasn’t echoing the do_shortcode statement.

    It should read:

    echo do_shortcode('[amazon-element asin="'. $asin .'" fields="title,lg-image,large-image-link,button"]');

Viewing 1 replies (of 1 total)
  • The topic ‘Shortcode not executing in PHP?’ is closed to new replies.