这个查询有什么问题?它总是返回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
);
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));
代码:
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;