0

我一直在开发一个使用自定义帖子类型和 CMB 插件的 Wordpress 主题。在我的本地服务器(MAMP)上一切正常,但是当我将它全部移动到我的实时服务器时,当我访问我的活动场地的页面时,我开始收到以下错误......

Parse error: syntax error, unexpected '[' in...on line 6

第 6 行开始以下代码:

$event = [
    'title'     => the_title('','',false),
    'id'        => get_the_ID(),
    'support'   => get_post_meta( $post->ID, '_ecmb_supporting_bands', true ),
    'datetime'  => get_post_meta( $post->ID, '_ecmb_datetime', true ),
    'desc'      => wpautop( get_post_meta( $post->ID, '_ecmb_event_desc', true ) ),
    'image'     => get_post_meta( $post->ID, '_ecmb_event_image', true ),
    'hlcolor'   => get_post_meta( $post->ID, '_ecmb_highlight_color', true ),
    'age'       => get_post_meta( $post->ID, '_ecmb_event_agelim', true ),
    'tixavail'  => get_post_meta( $post->ID, '_ecmb_tickets_avail', true ),
    'doorprice' => get_post_meta( $post->ID, '_ecmb_ticket_price_dp', true ),
    'advprice'  => get_post_meta( $post->ID, '_ecmb_ticket_price_ps', true ),
    'ticketurl' => get_post_meta( $post->ID, '_ecmb_tix_url', true ),
    'ticketloc' => get_post_meta( $post->ID, '_ecmb_ticket_loc', true ),
    'shorturl'  => get_post_meta( $post->ID, '_ecmb_short_url', true ),
    'artistbio' => wpautop( get_post_meta( $post->ID, '_ecmb_artist_bio', true ) ),
    'artistfb'  => get_post_meta( $post->ID, '_ecmb_artist_fb_url', true ),
    'artisttw'  => get_post_meta( $post->ID, '_ecmb_artist_tw_url', true ),
    'artistweb' => get_post_meta( $post->ID, '_ecmb_artist_web_url', true ),
];

我整晚都在绞尽脑汁想弄清楚这一点。我重新上传了网站,检查了我所有的代码是否有冲突的变量和其他东西,但我仍然无法弄清楚。我什至将数据库更改回我的本地主机并尝试了一下......在本地主机上工作正常。将其更改回实时服务器使其无法正常工作。该网站的其余部分也可以正常工作。

会发生什么?这是一个PHP问题吗?我的本地主机使用 PHP 5.4.10,我的实时服务器使用 PHP 5.3.27 ...

想法?

4

2 回答 2

0

您误解了 php 数组语法。

还从最后一项中删除逗号

语法应该是$event = array( items1, item2, item3 );用逗号()分隔的所有项目,。所以最后一项后不需要逗号。

将其用作:

$event = array(

     'title'     => the_title('','',false),

     //.........

     //rest of items

     //.........

     'artistweb' => get_post_meta( $post->ID, '_ecmb_artist_web_url', true )// remove comma from this line
);
于 2013-10-09T04:34:28.900 回答
0

PHP 5.4.x 有新的特性来声明数组,就像你在localhost. 在 PHP 5.3.x 或所有版本中,以下将起作用。

$event = array(
    'title'     => the_title('','',false),
    'id'        => get_the_ID(),
    'support'   => get_post_meta( $post->ID, '_ecmb_supporting_bands', true ),
    'datetime'  => get_post_meta( $post->ID, '_ecmb_datetime', true ),
    'desc'      => wpautop( get_post_meta( $post->ID, '_ecmb_event_desc', true ) ),
    'image'     => get_post_meta( $post->ID, '_ecmb_event_image', true ),
    'hlcolor'   => get_post_meta( $post->ID, '_ecmb_highlight_color', true ),
    'age'       => get_post_meta( $post->ID, '_ecmb_event_agelim', true ),
    'tixavail'  => get_post_meta( $post->ID, '_ecmb_tickets_avail', true ),
    'doorprice' => get_post_meta( $post->ID, '_ecmb_ticket_price_dp', true ),
    'advprice'  => get_post_meta( $post->ID, '_ecmb_ticket_price_ps', true ),
    'ticketurl' => get_post_meta( $post->ID, '_ecmb_tix_url', true ),
    'ticketloc' => get_post_meta( $post->ID, '_ecmb_ticket_loc', true ),
    'shorturl'  => get_post_meta( $post->ID, '_ecmb_short_url', true ),
    'artistbio' => wpautop( get_post_meta( $post->ID, '_ecmb_artist_bio', true ) ),
    'artistfb'  => get_post_meta( $post->ID, '_ecmb_artist_fb_url', true ),
    'artisttw'  => get_post_meta( $post->ID, '_ecmb_artist_tw_url', true ),
    'artistweb' => get_post_meta( $post->ID, '_ecmb_artist_web_url', true ),
);
于 2013-10-09T04:36:44.073 回答