Php 查询自定义帖子类型并从每个自定义帖子类型返回一篇帖子
我已经设置了一个查询来搜索我设置的一些自定义帖子类型。我可以让它显示所有的帖子,所以我知道它正在搜索我想要的自定义帖子类型。但我不知道如何让它只从我正在搜索的每个自定义帖子类型返回一篇帖子 示例:我有4种自定义帖子类型。CPT1,CPT2,CPT3,CPT4。我想从CPT1中得到一篇文章,从CPT2中得到一篇文章,等等。这样在循环中就会是:CPT1的标题,CPT2的标题,等等 然后我想我可以为每个自定义帖子类型做一个查询,并使每个类型都有自己的循环,但这似乎需要很多代码。感谢您在advanced中提供的任何帮助 这是我现在拥有的代码:Php 查询自定义帖子类型并从每个自定义帖子类型返回一篇帖子,php,wordpress,loops,post,custom-post-type,Php,Wordpress,Loops,Post,Custom Post Type,我已经设置了一个查询来搜索我设置的一些自定义帖子类型。我可以让它显示所有的帖子,所以我知道它正在搜索我想要的自定义帖子类型。但我不知道如何让它只从我正在搜索的每个自定义帖子类型返回一篇帖子 示例:我有4种自定义帖子类型。CPT1,CPT2,CPT3,CPT4。我想从CPT1中得到一篇文章,从CPT2中得到一篇文章,等等。这样在循环中就会是:CPT1的标题,CPT2的标题,等等 然后我想我可以为每个自定义帖子类型做一个查询,并使每个类型都有自己的循环,但这似乎需要很多代码。感谢您在advanced
$mystate = get_state();
// args
$args = array(
'numberposts' => -1,
'post_type' => array('CPT1','CPT2','CPT3','CPT4'),
'meta_key' => 'state_420',
'meta_value' => $mystate,
'order' => 'ASC',
);
/ query
$the_query = new WP_Query( $args );
?>
<?php
if ( $the_query->have_posts() ) : ?>
<?php
/* Start the Loop */
while ( $the_query->have_posts() ) : $the_query->the_post();
/**
* Run the loop for the search to output the results.
* If you want to overload this in a child theme then include a file
* called content-search.php and that will be used instead.
*/
?>
<li style="display: inline-block;"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>, </li>
<?php
endwhile;
the_posts_pagination( array( 'mid_size' => 2 ) );
else :
get_template_part( 'template-parts/content', 'none' );
endif; ?>
<?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>
$mystate=get_state();
//args
$args=数组(
“numberposts”=>-1,
'post_type'=>数组('CPT1'、'CPT2'、'CPT3'、'CPT4'),
“meta_key”=>“state_420”,
“meta_值”=>$mystate,
“订单”=>“ASC”,
);
/质疑
$thew_query=newwp_query($args);
?>
您应该传递此参数posts\u per\u page=>1我已经尝试过了,但是对于所有自定义帖子类型,它只返回一篇帖子