2016-11-22 131 views
0

我升級到Wordpress 4.6.1和一個日曆頁面,顯示來自許多不同類型的帖子的數據,開始顯示錯誤:升級到WordPress的4.6.1和現在「警告:爲foreach()提供的無效參數」

Warning: Invalid argument supplied for foreach() in /home/centkuti/public_html/wp-content/themes/central-square-theater/page-templates/page-calendar.php on line 117

在升級之前沒有發生這種情況,我檢查了代碼並沒有改變。這裏是行115至120:

<?php 
    $prepost = get_post_custom_values('pre_post_related_show', $row->post_id); 
    foreach($prepost as $v) 
    { 
    //echo $v; 
    } 
?> 

您的幫助表示讚賞。

+1

確保'$ prepost'是一個數組,而不是null或假,試圖來遍歷它之前。 – aynber

+1

此問題可能始終存在,但新安裝不再抑制該錯誤級別,或者配置爲在曾經抑制錯誤的位置顯示錯誤。無論如何,aynber的評論是正確的。 – MonkeyZeus

+0

你對一個有註釋的「foreach」有什麼期望? – zx485

回答

1

這應該工作

<?php 
$prepost = get_post_custom_values('pre_post_related_show', $row->post_id); 
if(is_array($prepost) && count($prepost)>0) { 
    foreach($prepost as $v) { 
    //echo $v; 
    } 
} 
?> 
+0

這工作!謝謝! –

相關問題