我有这样的代码在我的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