admin管理员组文章数量:1327308
i hope you are well today,
My question is just breif i am trying to query from a custom post type by a certain taxonomy only;
to keep it streamline lets use the below as an example;
Custom Post Type: 'Products';
Taxonomy: 'Categories';
Categories within 'Categories';
(1) Category 1 (2) Category 2 (3) Category 3
So i would like query posts from the Custom Post Type 'Products' and within 'Category 1'
How would this be done ?
Here is my code for what querying the custom post type and attempting to query the taxonomy category.
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$post_per_page = -1; // -1 shows all posts
$do_not_show_stickies = 1; // 0 to show stickies
$args=array(
'post_type' => 'products',
'taxonomy' => 'category-1',
'paged' => $paged,
'posts_per_page' => $post_per_page,
'order' => 'ASC',
);
$temp = $wp_query; // assign orginal query to temp variable for later use
$wp_query = null;
$wp_query = new WP_Query($args);
if( have_posts() ) : while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
i hope you are well today,
My question is just breif i am trying to query from a custom post type by a certain taxonomy only;
to keep it streamline lets use the below as an example;
Custom Post Type: 'Products';
Taxonomy: 'Categories';
Categories within 'Categories';
(1) Category 1 (2) Category 2 (3) Category 3
So i would like query posts from the Custom Post Type 'Products' and within 'Category 1'
How would this be done ?
Here is my code for what querying the custom post type and attempting to query the taxonomy category.
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$post_per_page = -1; // -1 shows all posts
$do_not_show_stickies = 1; // 0 to show stickies
$args=array(
'post_type' => 'products',
'taxonomy' => 'category-1',
'paged' => $paged,
'posts_per_page' => $post_per_page,
'order' => 'ASC',
);
$temp = $wp_query; // assign orginal query to temp variable for later use
$wp_query = null;
$wp_query = new WP_Query($args);
if( have_posts() ) : while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
Share
Improve this question
edited Apr 1, 2011 at 11:09
scribu
13.2k38 silver badges49 bronze badges
asked Apr 1, 2011 at 10:55
XavierXavier
4771 gold badge3 silver badges9 bronze badges
2 Answers
Reset to default 15There are 3 ways of doing that:
a)
...
'category_name' => 'category-1'
...
b)
...
'taxonomy' => 'category',
'term' => 'category-1',
...
c)
...
'tax_query' => array(
array( 'taxonomy' => 'category', 'field' => 'slug', 'terms' => array( 'category-1' ) )
)
...
More info: http://codex.wordpress/Function_Reference/WP_Query
tax_query array with taxonomy, field and terms. Where terms->business is the category of taxonomy-> job_category
$args = array(
'post_type' => 'featured_job',
'post_status' => 'publish',
'posts_per_page' => 9999999,
'orderby' => 'date',
'order' => 'DES',
'tax_query' => array(
array(
'taxonomy' => 'job_category',
'field' => 'slug',
'terms' => 'business',
),
),
);
本文标签: Query Custom Post by Taxonomy Category
版权声明:本文标题:Query Custom Post by Taxonomy Category 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742203414a2432374.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论