Php 警告:strtolower()要求wordpress中的参数1为字符串
我在wordpress中使用ajax开发了一个表单。它在localhost中运行良好,但当我在live server上上载代码时,在提交表单时会出现错误。错误为: 警告:strtolower()要求参数1为字符串,数组在第1426行的/home/content/26/11637326/html/surakshadal/wp includes/formatting.php中给出 查看我的代码: HTML: 下面是我在functions.php文件中的php代码:Php 警告:strtolower()要求wordpress中的参数1为字符串,php,jquery,ajax,wordpress,Php,Jquery,Ajax,Wordpress,我在wordpress中使用ajax开发了一个表单。它在localhost中运行良好,但当我在live server上上载代码时,在提交表单时会出现错误。错误为: 警告:strtolower()要求参数1为字符串,数组在第1426行的/home/content/26/11637326/html/surakshadal/wp includes/formatting.php中给出 查看我的代码: HTML: 下面是我在functions.php文件中的php代码: function review()
function review()
{
if($_POST['action']=='review_action')
{
$area=$_POST['area'];
$title=$_POST['title'];
$rev=$_POST['rev'];
$my_post = array(
'post_title' => $title,
'post_content' => $rev,
'post_status' => 'publish',
'post_type' => 'reviews',
'comment_status' => [ 'open' ],
);
$post1= wp_insert_post( $my_post );
if ( is_wp_error($post1) )
echo $post1->get_error_message();
}
wp_die();
}
add_action('wp_ajax_review_action', 'review');
add_action('wp_ajax_nopriv_review_action', 'review');
在您的代码中,我没有看到任何问题,但在您的
$my\u post
的注释状态中,您正在传递数组,因此请尝试从打开中删除[]
$my_post = array(
'post_title' => $title,
'post_content' => $rev,
'post_status' => 'publish',
'post_type' => 'reviews',
'comment_status' => 'open' ,//[ 'open' ], this is the array which may creates error
);
function review()
{
if($_POST['action']=='review_action')
{
$area=$_POST['area'];
$title=$_POST['title'];
$rev=$_POST['rev'];
$my_post = array(
'post_title' => $title,
'post_content' => $rev,
'post_status' => 'publish',
'post_type' => 'reviews',
'comment_status' => [ 'open' ],
);
$post1= wp_insert_post( $my_post );
if ( is_wp_error($post1) )
echo $post1->get_error_message();
}
wp_die();
}
add_action('wp_ajax_review_action', 'review');
add_action('wp_ajax_nopriv_review_action', 'review');
$my_post = array(
'post_title' => $title,
'post_content' => $rev,
'post_status' => 'publish',
'post_type' => 'reviews',
'comment_status' => 'open' ,//[ 'open' ], this is the array which may creates error
);