Php add_magic_quotes()在wordpress中不起作用
以下是插件运行的代码。它将CSV文件数据传递到MySQL。:/strong>Php add_magic_quotes()在wordpress中不起作用,php,wordpress,code-snippets,magic-quotes,Php,Wordpress,Code Snippets,Magic Quotes,以下是插件运行的代码。它将CSV文件数据传递到MySQL。:/strong> $new_post = array( 'post_title' => $row['Account Name'], 'post_content' => $row['Yellow Page Business Description'], 'post_status' => 'publish', 'post_author'
$new_post = array(
'post_title' => $row['Account Name'],
'post_content' => $row['Yellow Page Business Description'],
'post_status' => 'publish',
'post_author' => 1,
'post_type' => 'business',
'post_category' => array(0)
);
try
{
$result = wp_insert_post(add_magic_quotes($new_post), true);
if (is_wp_error($result)) {
$output .= '<p style="color:red;">ERROR LOADING CSV FILE</p>';
$output .= "<p style='color:red;'>Failed to import {$new_post['post_title']}</p>";
$output .= '<pre>'.$result->get_error_message().'</pre>';
}
else
{
$post_id = $result;
$new\u post=数组(
“post_title”=>$row[“帐户名”],
“发布内容”=>$row[“黄页业务描述”],
“发布状态”=>“发布”,
“后作者”=>1,
“post_type”=>“business”,
“post_类别”=>数组(0)
);
尝试
{
$result=wp\u insert\u post(添加魔法报价($new\u post),true);
如果(是错误($result)){
$output.='加载CSV文件时出错;
$output.=“
无法导入{$new_post['post_title']}
”;
$output.=''.$result->get_error_message();
}
其他的
{
$post_id=$result;
MySQL向其中报告:
$new_post = array(
'post_title' => $row['Account Name'],
'post_content' => $row['Yellow Page Business Description'],
'post_status' => 'publish',
'post_author' => 1,
'post_type' => 'business',
'post_category' => array(0)
);
try
{
$result = wp_insert_post(add_magic_quotes($new_post), true);
if (is_wp_error($result)) {
$output .= '<p style="color:red;">ERROR LOADING CSV FILE</p>';
$output .= "<p style='color:red;'>Failed to import {$new_post['post_title']}</p>";
$output .= '<pre>'.$result->get_error_message().'</pre>';
}
else
{
$post_id = $result;
[错误]WordPress数据库错误您的SQL语法有错误;请查看与您的MySQL服务器版本对应的手册,以了解正确的语法(near'))和(cj_posts.post_password='')和cj_posts.post_type='business'和'at line 1 for query SELECT DISTINCT SQL_CALC_FOUND_ROWS cj_posts.*从cj_posts左键连接cj_term_关系为trel ON(cj_posts.ID=trel.object_ID)左键连接cj_term_分类法为ttax ON((ttax.taxonomy='category'))和trel.term_分类法_ID=x.term_分类法左连接cj_术语作为tter ON(ttax.term_id=tter.term_id)左连接cj_注释作为cmt ON(cmt.comment_post_id=cj_posts.id),其中1=1和((())和(cj_posts.post_密码=“”)和cj_posts.post_类型='business'和(cj_posts.posts_状态='publish'))和post_类型='revision'))和post_status!='future'按cj_posts排序。post_标题类似“%”DESC,cj_posts.post_日期DESC限制0,10由require('wp-blog-header.php')生成,wp,wp->main,wp->query_posts,wp_query->query,wp_query->get_posts
cj_u是WordPress前缀
我认为这是因为使用了magic_quotes不起作用,所以它将CSV数据中的字符传递到MySQL,但没有正确转义。但我不能100%确定,也不确定要替换什么才能使其起作用。您不需要使用
添加magic_quotes
。从wp\u insert\u post
文档:
此函数在数据库中插入帖子(和页面)。它清理变量,进行一些检查,填充缺少的变量,如日期/时间等
重点是我的
add\u magic\u quotes
基本上是对数组进行迭代,并在每个元素上调用add\u slashes
。这是完全不必要的,因为wp\u insert\u post
将清理任何给定的输入。无论您希望add\u magic\u quotes
解决什么问题,它都不会解决。您能从上面给出一些例子吗代码?我无法理解文档。我更新了我的答案以澄清。add\u magic\u quotes
并不能解决您遇到的任何问题。