我試圖得到category
和我的自定義分類Type
的帖子的結果。我想這WordPress的query_posts爲多個變量不工作
$args = 'category=' . $cat . '&Type='.$type.'&order=ASC';
query_posts($args);
我從一個GET請求接收$cat
和$type
。問題是這是拉起屬於Type
分類標準的所有帖子到category
您的幫助表示讚賞。
謝謝!
我試圖得到category
和我的自定義分類Type
的帖子的結果。我想這WordPress的query_posts爲多個變量不工作
$args = 'category=' . $cat . '&Type='.$type.'&order=ASC';
query_posts($args);
我從一個GET請求接收$cat
和$type
。問題是這是拉起屬於Type
分類標準的所有帖子到category
您的幫助表示讚賞。
謝謝!
你可以試試這個
$args = 'cat=' . $cat . '&post_type='.$type.'&order=ASC';
query_posts($args);
更多參考: https://codex.wordpress.org/Function_Reference/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);
而是採用query_posts()
謝謝!
僅供參考...不要使用'query_posts',爲什麼? [點擊這裏](http://wordpress.stackexchange.com/questions/1753/when-should-you-use-wp-query-vs-query-posts-vs-get-posts) – Noman
謝謝你這麼多分享! –
請勿使用'query_posts()'獲取帖子。對於一般的後期查詢,請使用['WP_Query()'](https://codex.wordpress.org/Class_Reference/WP_Query)或['get_posts()'](https://codex.wordpress.org/Function_Reference/get_posts )。 –