警告:第9行/home/content/52/11847652/html/coupons/wp-content/themes/deals/taxonomy-coupon_store.php为foreach()提供的参数无效
这是给出此错误的url page。
<?php
$taxonomy='coupon_store';
$term = get_queried_object();
//get my store.
$store_obj = get_the_terms( $post->ID, 'coupon_store' );
foreach ( $store_obj as $element ) {
$store_id = $element->term_id;
$store_name = $element->name;
$store_description = $element->description;
$store_count = $element->count;
$store_url = get_term_link( $element, 'coupon_store' );
}
$store_url = get_metadata('coupon_store', $store_id, 'junkie_store_url', true);
$store_aff_url = get_metadata('coupon_store', $store_id, 'junkie_store_aff_url', true);
$store_image_preview = junkie_get_store_image_url($store_id, 'term_id', 100);
?>
答案 0 :(得分:0)
由于empty variable
而产生此错误。
您需要检查变量是否为空。
请参阅下面的示例代码,
$coupons = array();
if( !empty($coupons) )
{
foreach ($coupons as $coupon)
{
//Do your Stuff.
}
}
希望它能奏效。
答案 1 :(得分:0)
请检查
$post->ID
我认为post-&gt; ID为空白。请检查。
答案 2 :(得分:0)
<?php
$taxonomy='coupon_store';
$term = get_queried_object(); //get my store.
$store_obj = get_the_terms( $post->ID, 'coupon_store' );
if(!empty($store_obj))
{
foreach ( $store_obj as $element )
{
$store_id = $element->term_id;
$store_name = $element->name;
$store_description = $element->description;
$store_count = $element->count;
$store_url = get_term_link( $element, 'coupon_store' );
}
}
$store_url = get_metadata('coupon_store', $store_id, 'junkie_store_url', true);
$store_aff_url = get_metadata('coupon_store', $store_id, 'junkie_store_aff_url', true);
$store_image_preview = junkie_get_store_image_url($store_id, 'term_id', 100);
&GT;