此查询有什么问题?它总是返回NULL。
$recipes = $wpdb->get_results(
"SELECT ID FROM ".$wpdb->posts." WHERE post_author = %d AND post_status IN ('draft','publish') AND post_type = 'recipes' ", $current_user->ID
);
答案 0 :(得分:1)
get_results将输出类型作为第二个参数。如果你想这样做,你就错过了准备方法。它应该像
$recipes = $wpdb->get_results($wpdb->prepare ("SELECT ID FROM ".$wpdb->posts."
WHERE post_author = %d
AND post_status IN ('draft','publish')
AND post_type = 'recipes' ", $current_user->ID));
答案 1 :(得分:1)
<强>代码:强>
global $post;
global $wpdb;
$sel_query = "SELECT id FROM ".$wpdb->prefix."posts WHERE post_author = ".$current_user->ID." AND post_status IN ('draft','publish') AND post_type = 'recipes' ";
$totaldata = $wpdb->get_results($sel_query);
return $totaldata;