生成されたクエリは、すべての条件が真であることを期待:post_type
はpublish
するsocial
とpost_status
するsocial
またはpost
とcategory_name
のいずれかであることを。
一つの簡単な解決策ではなくWP_Query
を使用することです:
$query = new WP_Query(array(
'post_type' => array('social', 'post'),
'category_name' => 'social',
'post_status' => 'publish'
));
$posts = $query->posts;
を次に、クエリのwhere
一部を変更するposts_where
フィルタを使用することがあります。
add_filter('posts_where', 'my_posts_where', 10, 2);
function my_posts_where($where, $query) {
...modify $where...
return $where;
}
私は、文字列をスキップしますそこに特有のものはないからです。
"AND (wp_term_relationships.term_taxonomy_id IN (<number>))
AND wp_posts.post_type IN ('social', 'post') AND
((wp_posts.post_status = 'publish'))"
あなたはこのようなものに変換する必要があります:
"AND (((wp_term_relationships.term_taxonomy_id IN (<number>)
AND wp_posts.post_type = 'post') OR (wp_posts.post_type = 'social'))
AND (wp_posts.post_status = 'publish'))"
最後に、あなたはmy_posts_where
がないことを確認する必要がありますとにかく、$where
は、この(私のWordPressのインストールをテストした)のようになります。他のクエリを壊さないでください。私は$query
オブジェクトにあるインジケータを追加して、フィルタ内のこの特定のクエリを識別することができます。
ちょうど私が必要なもの!ありがとう! – jhummel