我试图将表和表字段作为变量插入,如
$meta = array(
'_wp_attached_file'=>$guid,
'_woocommerce_exclude_image'=>'0',
'_wp_attachment_metadata'=>''
);
foreach($meta as $key=>$value){
mysql_query("insert into $wpdb->postmeta (`post_id`,`$key`) values('$post_id','$value')") or die(mysql_error());
}
它给出错误
'字段列表'中的未知列'_wp_attached_file'
如何使用字段名称插入表格? (这是一个WordPress表)
答案 0 :(得分:0)
Wordpress的wp_postmeta
table只包含四列:
meta_id
post_id
meta_key
meta_value
你(可能)想要:
INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) VALUES
('$post_id', '$key', '$value')