У меня есть этот код в моей 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
Какое сообщение об ошибке у вас есть? –
Возможный дубликат [в чем проблема в этом запросе, он удалит все записи таблицы!] (Http://stackoverflow.com/questions/5018131/what-is-the-problem-in-this-query-it- will-delete-all-records-of-table) – mario