简体   繁体   中英

Wordpress- Echo PHP into Shortcode

I've run into a little bit of a snag with shortcodes. I want it to take the variable and put it in place for the text that should usually go there, but instead of working it just doesn't load it up, even though I've tested it with the echo to see if it's putting anything out and it is.

<?php 
    $artistslug = the_field('artist_cat_slug');
    echo $artistslug;    // Here for test reasons
    echo do_shortcode('[product_category category="'.$artistslug.'"]');
?>

Any help would be greatly appreciated.

Most probably, the_field() displays the value. The plugin you are using might have a corresponding function to return the value instead, for eg get_the_field() . Use that instead.

Edit after clarification in comments

From the documentation for the_field() ( emphasis mine):

Displays the value of the specified field. (this is the same as echo get_field($field_name) )

Exactly. Use get_field() instead.

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