简体   繁体   中英

Wordpress php shortcode inside a php

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?

<?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 .

一个班轮:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM