我正在尝试根据名为randomid的自定义字段值删除帖子。
$querystr = "
DELETE FROM $wpdb->posts LEFT JOIN $wpdb->postmeta
WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id
AND $wpdb->postmeta.meta_key = \'randomID\'
AND $wpdb->postmeta.meta_value = \'$randomID\'";
这让我觉得
DELETE FROM wp_posts LEFT JOIN wp_postmeta WHERE wp_posts.ID = wp_postmeta.post_id AND wp_postmeta.meta_key = \'randomID\' AND wp_postmeta.meta_value = \'070313wIOLTxv\';
但是我得到了一个mysql语法错误,我做错了什么?
最合适的回答,由SO网友:Mike Madern 整理而成
你没有ON
为您的LEFT JOIN
, 我想WHERE
您使用的声明必须是ON
陈述
您应该改用此查询:
$querystr = "
DELETE FROM $wpdb->posts
LEFT JOIN $wpdb->postmeta ON $wpdb->postmeta.post_id = $wpdb->posts.ID
WHERE $wpdb->postmeta.meta_key = \'randomID\'
AND $wpdb->postmeta.meta_value = \'$randomID\'";
此处引用:
http://dev.mysql.com/doc/refman/5.0/en/join.html