我试图创建一个字符串在我的WordPress网站使用字段从职位,以便我可以使用该字符串,以稍后运行脚本,但我有一个困难的时候,让字符串正确连接。下面是我正在运行的循环:
<?php
$args = array(
'post_type' => 'products',
'category_name' => $post_type
);
$query = new WP_Query( $args );
if( $query->have_posts() ) : while( $query->have_posts() ) : $query->the_post(); ?>
<div class="cell small-12 medium-6 large-3 product-cell text-center">
<div data-shopify-product="<?php the_field('product_id'); ?>"></div>
<a href="<?php echo get_permalink(); ?>"><button class="button large productDetailsButton">Details</button></a>
<div id="category-snippet-<?php the_field('product_id'); ?>"></div>
</div>
<?php
$powerReviewsScript = $powerReviewsScript . "
{
locale: 'en_US',
merchant_group_id: 79052,
page_id: '" . the_field('product_id') . "',
merchant_id: 127395,
api_key: '0d462e35-0345-4511-859e-03b0a65aea6d',
review_wrapper_url: 'http://yoursite.com/write-a-review/?pr_page_id=" . the_field('product_id') . "',
components: {
CategorySnippet: 'category-snippet-" . the_field('product_id') . "'
}
},"
?>
<?php endwhile; endif; wp_reset_postdata(); ?>
1PHP没有注入
the_field('product_id')
在绳子里。它显示为空的
2
\u字段('产品\u id')
每次在PHP中调用HTL时都会打印到HTL。
我是不是把这根弦编错了?可以用这种方式创建一个字符串吗?