我在安装 wordpress 时遇到问题。当我在本地工作时,此功能正常工作:
function get_images_from_media_library() {
$args = array(
'post_type' => 'attachment',
'post_mime_type' =>'image',
'numberposts' => -1,
'post_status' => null,
'post_parent' => null, // any parent
);
$attachments = get_posts($args);
$images = array();
if ($attachments) {
foreach ($attachments as $post) {
setup_postdata($post);
array_push($images, wp_get_attachment_image_src($post->ID, 'full')[0]);
}
}
return $images;
}
这会检索安装时附加到媒体的所有图像,并以数组的形式返回它们。
但是,当我将安装放在远程站点上时,当我尝试使用包含此功能的主题时出现此错误:
Parse error: syntax error, unexpected '[' in /hermes/bosoraweb133/b2623/ipg.yourdomaincom/98EMcBee/wp-content/themes/98emcbee/functions.php on line 52
第 52 行是 foreach 内的这一行:
array_push($images, wp_get_attachment_image_src($post->ID, 'full')[0]);
为什么我会在远程站点而不是本地站点上收到此错误?