0

I do not know, what is wrong with this code:

function my_wpcf7_save($cfdata) {

$formtitle = $cfdata->title;
$formdata = $cfdata->posted_data;   

if ( $formtitle == 'contactform1') {

    // access data from the submitted form
    $formfield = $formdata['name'];

    // create a new post
    $newpost = array( 
                  'post_title' -> $formdata['name']);
                  'post_content' -> $formdata['message']);
                  'post_status' -> 'publish');

    $newpostid = wp_insert_post($newpost);

    // add meta data for the new post
    add_post_meta($newpostid, 'email', $formdata['email']);
    add_post_meta($newpostid, 'subject', $formdata['subject']);
}

}
add_action('wpcf7_before_send_mail', 'my_wpcf7_save',1);

I got the error: Parse error: syntax error, unexpected T_OBJECT_OPERATOR, expecting ')' ... for this line: 'post_title' -> $formdata['name']);

As far as I know, the syntax is right, isn't it?

4

2 回答 2

3

请阅读马里奥在您的问题中的评论:

// create a new post
$newpost = array( 
              'post_title' => $formdata['name'],  <------------------ Here
              'post_content' => $formdata['message'], <-------------- Here
              'post_status' => 'publish');

更新:也替换->=>,如上所示。

于 2013-07-28T16:28:12.603 回答
2

我很确定:

$newpost = array( 
  'post_title' -> $formdata['name']);
  'post_content' -> $formdata['message']);
  'post_status' -> 'publish');

应该:

$newpost = array( 
  'post_title' => $formdata['name'],
  'post_content' => $formdata['message'],
  'post_status' => 'publish');

因为你在真正完成声明数组之前关闭了数组和语句。这就是我认为你至少试图做的事情。

于 2013-07-28T16:28:57.640 回答