[英]Wordpress Query Posts Taxonomy
I currently have a checkbox based search and filter on my wordpress site. 我目前在我的wordpress网站上有一个基于复选框的搜索和过滤器。
Basically it works using this wp_query 基本上可以使用此wp_query
$queryObject = new WP_Query(array("post_type"=>'toy','posts_per_page'=>999999, 'category__and' => $_POST['myListOfCategories']));
I want to move away from using categories (as it's making using the blog a pain) 我想放弃使用类别(因为使用博客变得很痛苦)
So I've set everything up using custom taxonomies now and notice there is no "taxonomy__and". 因此,我现在使用自定义分类法设置了所有内容,并注意到这里没有“分类法和”。
Does anyone know of a way to use WP_Query to search for posts using taxonomies in the same way category__and and works? 有谁知道使用WP_Query以相同的类别__和工作方式使用分类法搜索帖子的方法吗?
eg I pass multiple taxonomy id's and it only returns posts which have all of them linked. 例如,我传递了多个分类ID,并且它仅返回链接了所有分类的帖子。
From http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters 来自http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters
You should be able to use something like this; 您应该可以使用这样的东西;
$args = array(
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'movie_genre',
'field' => 'slug',
'terms' => array( 'action', 'comedy' )
),
array(
'taxonomy' => 'actor',
'field' => 'id',
'terms' => array( 103, 115, 206 ),
'operator' => 'NOT IN'
)
)
);
$query = new WP_Query( $args );
You have pass multiple taxonomy in Query_posts in Wordpress 您已经在Wordpress的Query_posts中通过了多个分类法
See below URL It is very help full to you:- 参见下面的URL,这对您有很大帮助:-
https://wordpress.stackexchange.com/questions/25999/how-to-pass-url-parameters-for-advanced-taxonomy-queries-with-multiple-terms-for https://wordpress.stackexchange.com/questions/25999/how-to-pass-url-parameters-for-advanced-taxonomy-queries-with-multiple-terms-for
https://wordpress.stackexchange.com/questions/10713/wp-3-1-getting-tax-query-to-work-in-query-posts https://wordpress.stackexchange.com/questions/10713/wp-3-1-getting-tax-query-to-work-in-query-posts
Query multiple custom taxonomy terms in Wordpress 2.8? 在Wordpress 2.8中查询多个自定义分类术语?
or try it 或尝试一下
query_posts( array(
'tax_query' => array(
array(
'taxonomy' => 'tax1',
'field' => 'slug',
'terms' => array('term1', 'term2'),
'operator' => 'OR'
),
array(
'taxonomy' => 'tax2',
'field' => 'slug',
'terms' => array('term3', 'term4'),
'operator' => 'AND'
),
) );
With the help of the other posters here is the final answer to my question: 在其他海报的帮助下,这是我的问题的最终答案:
$queryObject = new WP_Query(array("post_type"=>'toy','posts_per_page'=>10,'tax_query' => array( array( 'taxonomy' => 'toy_cats', 'field' => 'id', 'terms' => array(14,20,39,42), 'operator' => 'AND' ) )));
The above code will only show posts that have the "toy" post type, is in the taxonomy "toy_cats" and is is assigned to ALL the following term id's 14 AND 20 AND 39 AND 42 上面的代码将仅显示具有“玩具”帖子类型,分类法为“ toy_cats”且被分配给以下所有以下术语id的所有帖子:14 AND 20 AND 39 AND 42
Hope this helps someone else. 希望这对其他人有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.