[英]How to get ACF value into PHP Shortcode for WordPress
I'm trying embed a Gravity Form in my PHP code.我正在尝试在我的 PHP 代码中嵌入重力形式。 I'm unable to 'get' the field from ACF.
我无法从 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" );;¶meter_name2=value2"]'); ?><?php endwhile; ?>
You need to pull the php execution part out of the string...您需要将 php 执行部分从字符串中拉出...
echo do_shortcode('[gravityform id=18 title=false description=false field_values="KJFKSLX=' . get_field("sellprice") . '¶meter_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).如果
$value
是您想要发送到简码的 php 变量(因为您对简码字符串使用单引号),则同样如此。
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.'¶meter_name2=value2"]');
endwhile;
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.