admin管理员组文章数量:1387337
I'm aware there are several other posts that cover similar ground to what I'm about to ask.
I have three custom post types running, in addition to 'posts'. I want to run a loop that pulls all posts categorised under a particular category
<?php
$args = array(
'post_type' => 'testimonial',
'posts_per_page' => 1,
'tax_query' => array(
array (
'taxonomy' => 'testimonial_category',
'field' => 'slug',
'terms' => 'home'
)
)
);
$query = new WP_Query( $args );
$postcount = 0;
?>
<?php if ($query->have_posts()) : ?>
<?php while ($query->have_posts()) : $query->the_post(); ?>
<?php $postcount++; ?>
//loop here
<?php wp_reset_query(); ?>
This is the code I have at the moment, not sure how I condense this into pulling in multiply post types from one category.
I'm aware there are several other posts that cover similar ground to what I'm about to ask.
I have three custom post types running, in addition to 'posts'. I want to run a loop that pulls all posts categorised under a particular category
<?php
$args = array(
'post_type' => 'testimonial',
'posts_per_page' => 1,
'tax_query' => array(
array (
'taxonomy' => 'testimonial_category',
'field' => 'slug',
'terms' => 'home'
)
)
);
$query = new WP_Query( $args );
$postcount = 0;
?>
<?php if ($query->have_posts()) : ?>
<?php while ($query->have_posts()) : $query->the_post(); ?>
<?php $postcount++; ?>
//loop here
<?php wp_reset_query(); ?>
This is the code I have at the moment, not sure how I condense this into pulling in multiply post types from one category.
Share Improve this question asked Jun 18, 2013 at 13:41 dannyw24dannyw24 4511 gold badge6 silver badges16 bronze badges2 Answers
Reset to default 39Just change the post_type
bit to:
'post_type' => array('testimonial', 'other_post_type', 'another-post-type'),
Assuming that taxonomy is valid across all 3 post types. Otherwise you'll have to leave that out.
Why? You can pass an array to post_type
field.
$args = array(
'post_type' => array( 'testimonial', 'post' ),
'posts_per_page' => 1,
);
$query = new WP_Query( $args );
Edit Note:
To query for multiple post types you would add an array()
of post types instead of just querying for one.
本文标签: phpQuery multiple custom post types in single loop
版权声明:本文标题:php - Query multiple custom post types in single loop 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744515295a2610127.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论