2016-05-23 2 views
0

を働いていません。私は私がGETリクエストから$cat$typeを受け付けております。このWordpressのquery_postsは私が<code>category</code>と私のカスタム分類<code>Type</code>を持っているポストの結果を取得しようとしていた

$args = 'category=' . $cat . '&Type='.$type.'&order=ASC'; 
    query_posts($args); 

をしようとしています。問題は、category

へのTypeタクソノミに属するすべての投稿を引き上げていることです。

ありがとうございます!

+0

投稿をフェッチするために 'query_postsを()'を使用しないでください。一般的なポストクエリで、[ 'WP_Query()'](https://codex.wordpress.org/Class_Reference/WP_Query)または[ 'get_posts()'](https://codex.wordpress.org/Function_Reference/get_postsを使用)。 –

答えて

0

あなたがより多くの参考のため、この

$args = 'cat=' . $cat . '&post_type='.$type.'&order=ASC'; 
    query_posts($args); 

試すことができます。 https://codex.wordpress.org/Function_Reference/query_posts

+0

は機能しません。私はあまりにも前にそれをしました。 –

1

を私はこれをしなければならなかった。代わりにquery_posts()

を使用して

$args = array(
    'post_type' => 'post', 
    'tax_query' => array(
     'relation' => 'AND', 
     array(
      'taxonomy' => 'category', 
      'field' => 'slug', 
      'terms' => array($cat), 
     ), 
     array(
      'taxonomy' => 'Type', 
      'field' => 'slug', 
      'terms' => array($type), 
     ), 
    ), 
); 
$query = new WP_Query($args); 

ありがとうございました!

+0

ちょうどについて...なぜ、 'query_posts'を使用しないでください? [こちらをクリック](http://wordpress.stackexchange.com/questions/1753/when-should-you-use-wp-query-vs-query-posts-vs-get-posts) – Noman

+0

がためにどうもありがとうございます共有! –

関連する問題

 関連する問題