3

I am setting up custom fields in Wordpress in order to be able to enter an ASIN number from amazon and have it pass through the shortcode I have in the template file.

In my custom field I am using Name:asin and Value:(whatever ASIN # I want to put in)

Here is what I have currently in the template file:

<?php $asin = get_post_meta( $post->ID, 'asin', true); ?>

<?php echo $asin ?>

<?php echo do_shortcode( '[scrapeazon asin="B002P4SMHM" width="650" height="400" border="false" country="us")]' );?>

I am trying to put the variable $asin into the scrapeazon shortcode that I have, something like this:

<?php echo do_shortcode( '[scrapeazon asin="<?php echo $asin ?" width="650" height="400" border="false" country="us")]' );?>

But this is not working, any ideas?

1 Answer 1

2

What about this approach?

function my_shortcode_function( $attributes ) {
    global $post;

    // manage attributes
    $a = shortcode_atts( array(
        'foo' => 'something',
        'bar' => 'something else',
    ), $attributes );

    // do sth with the custom field
    $asin = get_post_meta( $post->ID, 'asin', true);
}

add_shortcode('my_shortcode', 'my_shortcode_function');

So don 't try to get the custom value in the template. Just deal with it in the shortcode function. Through the global declared $post variable it should work. Yes, global ist not very clean. But it 's wordpress ...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.