我试图得到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 )。 –