我目前正在制作一个插件,需要一些关于主题的帮助。我想使用所有的the_loop善,但需要一个原始的SQL查询。
/**
* Get all the posts neccessarry
* return array<WP_Post> returns an array of all constructed WP_Posts
*/
public static function get_posts($o){
global $wpdb;
$posts = array();
$tax= $o['tax'];
$q=$wpdb->get_results(
"SELECT * FROM {$wpdb->posts} p
LEFT OUTER JOIN
(SELECT * FROM {$wpdb->postmeta}
WHERE meta_key='/$p/_faq_prio'
GROUP BY post_id
) AS pm
ON ( p.ID = pm.post_ID ),
{$wpdb->term_relationships} t
WHERE p.post_type='faq' AND t.object_id = p.ID AND t.term_taxonomy_id = '{$tax}'
ORDER BY pm.meta_value ASC, ISNULL(pm.meta_key)", OBJECT_K);
foreach ($q as $p) {
array_push($posts, get_post($p) );
}
return $posts;
}
我有以下问题: