我试图将联系表单(CF7)中的数据插入到两个不同的表中 我非常确定我的代码是正确的,但仍然没有
这是代码
remove_all_filters ('wpcf7_before_send_mail');
add_action( 'wpcf7_before_send_mail', 'my_conversion' );
function my_conversion( $cf7 )
{
$email = $cf7->posted_data["email"];
$name = $cf7->posted_data["lastname"];
$tel = $cf7->posted_data["cf_3"];
$fonction = $cf7->posted_data["cf_1"];
$entreprise = $cf7->posted_data["cf_2"];
$newsletter = $cf7->posted_data["newsletter"];
insert($email, $name, $tel, $fonction,$entreprise,$newsletter);
}
function insert($email, $name, $tel, $fonction,$entreprise,$newsletter)
{
global $wpdb;
$wpdb->insert("wp_wysija_user", array(
"user_id" => NULL,
"wpuser_id" =>"0",
"email" => $email,
"firstname" => "",
"lastname" => $name,
"ffonc" => $fonction,
"fent" => $entreprise,
"ftel" => $tel,
"ip" => "0",
"confirmed_ip" => NULL,
"confirmed_at" => NULL,
"last_opened" => NULL,
"last_clicked" => NULL,
"keyuser" => NULL,
"created_at" => "",
"status" => "0",
"domain" => ""
));
if($newsletter == "oui")
{
$wpdb->insert("wp_wysija_user_list", array(
"list" => "3",
"user_id" => NULL,
"sub_date" => "1430666348",
"unsub_date" => "0"
));
}
}
我知道有另一个插件可以完成这项工作,但我宁愿按照自己的方式去做
谢谢, 雷米。
答案 0 :(得分:0)
执行步骤:
启用WP Debug并查看是否出现明显的错误或警告
检查是否调用了 my_conversion 功能,例如写
回声“我被称为”;死;很可能 wpdb->插入无法正常工作
尝试以下方法:
var_dump( $wpdb->last_query );
或
$wpdb->print_error()
由于您最有可能在ajax请求中执行此操作,请确保将调试结果写入日志文件或确保您可以在屏幕上或控制台中查看结果。