0
私は次の機能で苦労しています。タイトルにcurrentUserName
の投稿を更新したいと思います。特定のIDで投稿を更新する
私は次のことをやっている:
$id = (int)$wpdb->get_row("SELECT ID FROM wp_posts WHERE post_title = '" . $current_user->user_login . "' && post_status = 'draft' && post_type = 'post' ", 'ARRAY_N');
// Update post
$my_post = array(
'ID' => $id,
'post_title' => $current_user->user_login,
'post_content' => $current_user->user_email,
);
// Update the post into the database
wp_update_post($my_post);
しかし、私が手$id
は1
であるため、ポストは更新されません。エラーとして私は得る:
無効な投稿ID。
私が間違っていることは何ですか?
このスニペットを試してみてください?管理者としてログインしている場合は、管理者のユーザー名としてpost_title、投稿としてステータスを入力し、投稿として入力しようとしています。あなたは1の結果を得ていますか? –
@MujeebuRahmanはい。ポストIDを取得したいと思います。ポストIDには、ポストIDのユーザー名が入ります。 – mrquad