奇怪的T_Variable错误

时间:2013-12-21 08:17:57

标签: php mysql wordpress syntax

我正在尝试编写一个PHP脚本,以自动发布到WordPress数据库中的一些数据。

我一直收到T_VARIABLE错误,但无法弄清楚我做错了什么。

Parse error: syntax error, unexpected T_VARIABLE in c/public_html/example.com/wp-content/themes/twentyeleven/exampletemplatefile.php on line 50

第50行

$linkid = wp_insert_post( $post, $wp_error );

脚本的其余部分是:

 <?php
    /*
    Template Name: example template file 3
    */
    ?>
    <?php get_header(); ?>
    <?php
    $result = mysql_query("SELECT * FROM `events` WHERE wp_posted='0' LIMIT 1");

    while($row = mysql_fetch_array($result))
      {             
         $IDID = $row['ID'];
        $stats_ID = $row['stats_ID'];
        $Date = $row['Date'];
        $Competition_ID = $row['Competition_ID'];
        $Competition = $row['Competition'];
        $compgroup = $row['compgroup'];
        $Home_ID = $row['Home_ID'];
        $Home = $row['Home'];
        $Homeshort = $row['Homeshort'];
        $HomePath = $row['HomePath'];
        $Away_ID = $row['Away_ID'];
        $Away = $row['Away'];
        $AwayShort = $row['AwayShort'];
        $AwayPath = $row['AwayPath'];
        $Status = $row['Status'];
        $wp_posted = $row['wp_posted'];
        $wp_url = $row['wp_url'];
        $wp_post_id = $row['wp_post_id'];
    }



    $title = "hi"; 

    $description = "des hi";

    $ccat1 = "1";

    // Create post object
    $my_post = array(
      'post_title'    => "$title",
      'post_content'  => "$description",
      'post_status'   => 'publish',
      'post_author'   => 1,
      'post_category' => "$ccat2"

    )

    $linkid = wp_insert_post( $post, $wp_error );

    mysql_query("UPDATE events SET wp_post_id='$linkid'
    WHERE ID='$IDID' ");

    mysql_query("UPDATE events SET wp_posted='1'
    WHERE ID='$IDID' ");

    $permalink = get_permalink( $linkid ); 
    echo "Title: $title <br />";
    echo "Description: $description <br /><br />";

    ?>

我说它很奇怪的原因是我检查了缺少的括号并删除了部分脚本以尝试调试。如果我删除$linkid及其下面的所有内容,则只有带有标题的空白WordPress页面没有错误。如果我只删除$linkid下面的部分代码,我仍会得到相同的错误,尽管在不同的行上。

任何帮助都非常感激。

3 个答案:

答案 0 :(得分:1)

你之前错过了分号:

$my_post = array(
      'post_title'    => "$title",
      'post_content'  => "$description",
      'post_status'   => 'publish',
      'post_author'   => 1,
      'post_category' => "$ccat2"

    )

应该是

$my_post = array(
      'post_title'    => "$title",
      'post_content'  => "$description",
      'post_status'   => 'publish',
      'post_author'   => 1,
      'post_category' => "$ccat2"

    );

答案 1 :(得分:1)

第48行缺少分号。不确定这是否是解决办法,但这可能是问题所在。

$my_post = array(
  'post_title'    => "$title",
  'post_content'  => "$description",
  'post_status'   => 'publish',
  'post_author'   => 1,
  'post_category' => "$ccat2"

) // <------- here semicolon is missing.

$linkid = wp_insert_post( $post, $wp_error );

答案 2 :(得分:0)

添加分号

 $my_post = array(
      'post_title'    => "$title",
      'post_content'  => "$description",
      'post_status'   => 'publish',
      'post_author'   => 1,
      'post_category' => "$ccat2"

    ); // HERE