我正在使用 wordpress 并遇到一个奇怪的错误。我正在尝试使用 $wptb->insert
将数据插入表中,但它每次都会添加三个记录。我检查了这个 Wordpress insert query runs 3 times但这对我没有帮助。这是我的代码
添加空白页
add_submenu_page('', 'Duplicate', 'Duplicate', 'manage_options', 'lead-clone', 'clone_lead' );
函数 clone_lead
function clone_lead()
{
global $wpdb;
$table_name = $wpdb->prefix . "leads";
$mycheckdata=array(
'author'=>'1',
'lead_submits_counts'=>'0',
'templateid'=>'12423432',
'template_title'=>'sdgfsg adas asdfsd',
'showtext'=>'asdgsfg',
'fieldtype'=>'gfsdgd',
'guid'=>'asdgfg',
'wsdl'=>'ASFasdfsdgfg'
);
$create=$wpdb->insert($table_name, $mycheckdata);
die;
}
请告诉我哪里错了。谢谢
最佳答案
试试这个
function clone_lead()
{
global $wpdb;
$table_name = $wpdb->prefix . "leads";
$mycheckdata=array(
'author'=>'1',
'lead_submits_counts'=>'0',
'templateid'=>'12423432',
'template_title'=>'sdgfsg adas asdfsd',
'showtext'=>'asdgsfg',
'fieldtype'=>'gfsdgd',
'guid'=>'asdgfg',
'wsdl'=>'ASFasdfsdgfg'
);
$create=$wpdb->insert($table_name, $mycheckdata);
//or you can use
$wpdb->replace($table_name, $mycheckdata);
if($wpdb->insert_id!="")
return true;
die;
}
关于php - Wordpress 插入查询一次添加三条记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39255352/