【发布时间】:2017-05-02 06:33:29
【问题描述】:
我猜这是解析的问题,但经过几个小时后无法弄清楚。我接近解决方案,但卡住并开始让我发疯!
问题:我无法动态获取摘录(描述),因为看起来我的变量 $my_id 在以下情况下返回 null我将它推入函数 get_the_excerpt()
<?php ob_start(); ?>
{{ data[ index ].option_id }}
<?php $my_id = ob_get_clean(); ?>
<?php $product_description = get_the_excerpt($my_id); ?>
<span class="radio_button_desc"><?php echo apply_filters( 'woocommerce_composited_product_excerpt', wpautop( do_shortcode( wp_kses_post( $product_description ) ) ), $product_id, $component_id, $composite ); ?></span>
我已经尝试过像下面这样直接推送 id:
<?php $product_description = get_the_excerpt(123456); ?>
你猜怎么着?它正在工作。
我还尝试将 解析 $my_id 为 (int)。我的 gettype() 将它作为 int 返回,但在这种情况下我的变量返回“0”。
echo $my_id 正在返回正确的数字 (id),所以当我将它推入 get_the_excerpt($my_id);
有什么线索吗?
干杯!
编辑 1:
我已使用 vardump 和 print_r 更新了我的代码以查看返回值。
<?php ob_start(); ?>
{{ data[ index ].option_id }}
<?php $my_id = ob_get_clean(); ?>
<?php var_dump($my_id); ?>
<?php $product_description = get_the_excerpt( $my_id ); ?>
<?php print_r(get_the_excerpt( $my_id )); ?> <!-- return nothing */ -->
<span class="radio_button_desc"><?php echo apply_filters( 'woocommerce_composited_product_excerpt', wpautop( do_shortcode( wp_kses_post( $product_description ) ) ), $product_id, $component_id, $composite ); ?></span>
输出:
输出 当我通过添加 $my_id = is_int($my_id) 将其解析为 integer 时? $my_id : (int) $my_id; :
这基本上是返回我实际帖子的摘录,不是动态地使用 $my_id 的 id。
【问题讨论】: