Wordpress插件PHP解析错误:语法错误,意外' {',期待')'

时间:2014-07-01 08:26:51

标签: php wordpress wordpress-plugin

我在其他人构建的Wordpress网站上做了一些工作。他们制作了一个自定义插件,但不再与该公司合作。该插件在实际网站上加载但不会加载到测试服务器上,因此很难处理这些更改。

在测试服务器上加载插件会出现错误:

Parse error: syntax error, unexpected '{', expecting ')' in wp-content/plugins/uni-todays-program/todays-program.php on line 221

第221行是:

 $query = new WP_Query( [

周围的代码是:

// [today]
function today_func( $atts ) {

    // Retrieve current days schedule
    $today = getdate();
    $query = new WP_Query( [
      'post_type' => 'day_entry',
      'year' => $today["year"], 
      'monthnum' => $today["mon"], 
      'day' => $today["mday"] , 
      'post_status' => array('publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash')
    ]  );
    $day_type = $query->post->day_type;
    $query = new WP_Query( ['post_type' => 'day_type','name' => $day_type] );
    return $query->post->post_content;

}
add_shortcode( 'today', 'today_func' );

我只是一个前端人员,所以我的PHP非常有限但我无法看到这个问题。没有需要关闭的开放(

我做谷歌并发现了一些暗示它是php版本的东西但是我已经改变了所以现场和测试服务器都是5.4。

有人能引导我朝着正确的方向前进吗?

1 个答案:

答案 0 :(得分:2)

[]是数组声明的简短语法,如果测试服务器具有 php 5.4 或更高版本,它应该有效。

如果由于某种原因问题仍然存在,请尝试将代码更改为:

// [today]
function today_func( $atts ) {

    // Retrieve current days schedule
    $today = getdate();
    $query = new WP_Query( array(
      'post_type' => 'day_entry',
      'year' => $today["year"], 
      'monthnum' => $today["mon"], 
      'day' => $today["mday"] , 
      'post_status' => array('publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash')
    )  );
    $day_type = $query->post->day_type;
    $query = new WP_Query( array('post_type' => 'day_type','name' => $day_type) );
    return $query->post->post_content;

}
add_shortcode( 'today', 'today_func' );
相关问题