-1

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ファイルで以前に定義されています

4

4 に答える 4

1

削除は、* 文字なしで記述する必要があります。

于 2013-03-27T17:06:41.900 に答える
0

Try using $user_ID = get_current_user_id(); after global $current_user;. or get_currentuserinfo() after declaring $current_user; and then get the current user id by $user_ID = $current_user->ID. For more info of getting the current user logged in See http://codex.wordpress.org/Function_Reference/get_currentuserinfo

于 2013-03-28T06:45:25.470 に答える
0

クエリは次のようになります。

DELETE FROM table WHERE ....;

あなたの場合:

"DELETE FROM wp_posts WHERE post_author = $userID;"
于 2013-03-27T17:07:01.637 に答える
0

値を ' で囲む必要があります

そのようです:

$wpdb = "DELETE FROM wp_posts WHERE post_author = '$userID';"
于 2013-03-27T17:07:22.960 に答える