【发布时间】:2013-03-27 17:04:43
【问题描述】:
我的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定义在哪里? -
你有什么错误信息?
-
$query = "DELETE FROM {$wpdb->posts} WHERE post_author='$current_user->ID'"; $id = $wpdb->query($query); return $id;