解析错误:语法错误,意外的T
我不知道,这段代码有什么问题:
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);
我得到了错误: 解析错误:语法错误,意外的T_OBJECT_OPERATOR,期待')' ...对于这一行:'post_title' - > $ formdata ['name']);
据我所知,语法是正确的,不是吗?
请在你的问题中阅读马里奥的评论:
// create a new post
$newpost = array(
'post_title' => $formdata['name'], <------------------ Here
'post_content' => $formdata['message'], <-------------- Here
'post_status' => 'publish');
更新:同样替换->
with =>
,如上所示。
我很确定这一点:
$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');
就像你在实际完成声明数组之前关闭了数组和声明一样。 这就是我认为你至少想要做的事情。
链接地址: http://www.djcxy.com/p/69441.html上一篇: Parse error: syntax error, unexpected T
下一篇: Parse error: syntax error, unexpected '<' in functions.php