移动到在线服务器时自定义帖子类型字段不起作用

时间:2013-10-09 04:31:36

标签: php wordpress

我一直在开发一个使用自定义帖子类型和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 ),
];

我整夜都在试图解决这个问题。我重新上传了网站,检查了所有代码是否存在冲突的变量和其他内容,我仍然无法弄明白。我甚至将数据库更改回我的localhost并尝试了...在localhost上运行正常。将其更改回实时服务器使其无法正常工作。网站的其余部分也可以正常工作。

可能会发生什么?这是一个PHP问题吗?我的localhost使用PHP 5.4.10,我的实时服务器使用PHP 5.3.27 ...

思想?

2 个答案:

答案 0 :(得分: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
);

答案 1 :(得分:0)

PHP 5.4.x有new feature来声明数组,就像你在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 ),
);