0

Hello and thank you very much for your help. Im trying to personalize a theme in Wordpress but i'm having problems with PHP.

My problem is.. i have 2 php codes and i need to intregate both and i don't know how.

First code (working):

<?php echo do_shortcode( '[products skus="XXX" orderby="date" order="desc"]' ); ?>

Second code: (working):

<?php $key="_vb_artist_sku"; echo get_post_meta($post->ID, $key, true); ?>

My problem is i need to replace the "XXX" from the first code with de result of the second code. i try something like this:

<?php echo do_shortcode( '[products skus="<?php $key="_vb_artist_sku"; echo get_post_meta($post->ID, $key, true); ?>" orderby="date" order="desc"]' ); ?>

but does not work.

Can anyone help me please?

1
  • Your trying to make a declaration($key="_vb_artist_sku";) in a echo statement? That won't work! Also never have 2x php tags(<?php ?>) inside the other! Commented Nov 14, 2014 at 22:13

2 Answers 2

1
<?php
    $key = "_vb_artist_sku";
    $sku = get_post_meta($post->ID, $key, true);
    echo do_shortcode('[products skus="'.$sku.'" orderby="date" order="desc"]');
?>

I've used the string concatenation operator . to alter the string before passing it to do_shortcode.

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

1 Comment

That works =), thank you very much for your time, example and help!
0

A one liner:

echo do_shortcode( sprintf( '[products skus="%s" orderby="date" order="desc"]', get_post_meta($post->ID, '_vb_artist_sku', true ) ) );

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.