[英]500 Internal server error with new php files on server (Wordpress/Woocommerce)
[英]500 Internal Server Error in PHP 8.1 Array with wordpress
Jut 將 wordpress 和 woocommerce 更新到最新版本。 不幸的是,我在以下幾行中的某處獲得了 500 個內部服務器:
add_action( 'woocommerce_before_shop_loop_item', 'attribute_img_loop', 20 );
function attribute_img_loop() {
global $post;
$attribute_names = array( 'pa_sertifikalar' ); // Add attribute names here and remember to add the pa_ prefix to the attribute name
// echo '<script>alert('.$attribute_names.');</script>';
foreach ( $attribute_names as $attribute_name ) {
$taxonomy = get_taxonomy( $attribute_name );
if ( $taxonomy && ! is_wp_error( $taxonomy ) ) {
$terms = wp_get_post_terms( $post->ID, $attribute_name );
$terms_array = array();
if ( ! empty( $terms ) ) {
echo '
<table class="combs" cellspacing="0">
<tbody>
<tr>
<td>
<ul class="nm-variation-control ul-control-certificate">';
foreach ( $terms as $term ) {
$thumb_id = get_woocommerce_term_meta( $term->term_id, 'thumbnail_id', true );
$image_id = absint( get_term_meta( $term->term_id, 'nm_pa_image_thumbnail_id', true ) );
$img_src = ( $image_id ) ? wp_get_attachment_url( $image_id ) : '';
$archive_link = get_term_link( $term->slug, $attribute_name );
$full_line = '<li><div class="lcrap"><img id="c'. $image_id .'" data-src="'. $img_src .'" alt="" class="lazyload" alt="'. $term->name .'" /></div></li>';
array_push( $terms_array, $full_line );
}
// echo $taxonomy->labels->name . ' ' . implode( $terms_array, '-- ' );
echo implode( $terms_array, '');
echo '</ul>
</td>
</tr>
</tbody>
</table>';
}
}
}
}
剛剛添加了echo '<script>alert('.$attribute_names.');</script>';
從$attribute_names = array( 'pa_sertifikalar' );
檢查 output 部分並看到它返回一個
function Array() {
[native code]
}
知道這里發生了什么嗎? 使用 PHP 8.1
根據評論中的討論,解決方法是將implode( $terms_array, '')
更改為implode('', $terms_array)
。
從歷史上看,這些參數的順序無關緊要,但是從 PHP 7.4 開始,首先傳遞數組已被棄用,並在 PHP 8.0 中被完全刪除。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.