简体   繁体   中英

How to get ACF value into PHP Shortcode for WordPress

I'm trying embed a Gravity Form in my PHP code. I'm unable to 'get' the field from ACF.

<?php while ( have_posts() ): the_post(); ?><?php echo do_shortcode('[gravityform id=18 title=false description=false field_values="KJFKSLX=$value = get_field( "sellprice" );;&parameter_name2=value2"]'); ?><?php endwhile; ?>

You need to pull the php execution part out of the string...

echo do_shortcode('[gravityform id=18 title=false description=false field_values="KJFKSLX=' . get_field("sellprice") . '&parameter_name2=value2"]');

Same goes for $value if that is a php variable you want sent to the shortcode (since you're using single quotes for your shortcode string).

Try this code.

<?php 
    while(have_posts()): the_post();
        $value = get_field("sellprice");
        echo do_shortcode('[gravityform id="18" title="false" description="false" field_values="KJFKSLX='.$value.'&parameter_name2=value2"]');
    endwhile;
?>

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