我有這樣的代碼在我的functions.php
global $current_user;
$userid = $current_user->ID;
$args = array(
'post_type' => 'listings',
'post_status' => 'publish',
'author' => $userid
);
$the_posts = get_posts ($args); // get the published posts for that author
$post_count = count($the_posts); // count the number of published posts for the author
$N = 2; // set number for max posts per user
if ($post_count > $N) {
if (current_user_is('s2member_level1')) {
// This is where I want to delete from wp_post where post_author = $userID
}
}
我不是SQL查詢足夠熟悉弄清楚爲什麼它不工作。我試過
$wpdb = "DELETE FROM wp_posts WHERE post_author = $userID;"
和
$wpdb->query("DELETE FROM wp_posts WHERE post_author = $userID;");
全球WPDB $;是在我的php文件中更早定義的
定義了「$ wpdb」的位置? – chriz 2013-03-27 17:06:15
你有什麼錯誤信息? – 2013-03-27 17:06:47
可能重複[在這個查詢中有什麼問題,它會刪除表的所有記錄!](http://stackoverflow.com/questions/5018131/what-is-the-problem-in-this-query-it-將刪除所有記錄的表) – mario 2013-03-27 17:09:07