我有三个共享类别的CPT(slug = whats-new id = 1373)。我可以访问档案页面(“ category-whats-new.php”或archive.php),以仅显示该类别的帖子,但每个日期,或仅显示所有类别的帖子,但不显示特定日期。我希望我的存档页面仅按日期显示来自最新消息(来自所有post_types)的帖子,因此,当我使用“存档”小部件并单击一个月时,将显示该月来自cat whats-new的帖子。
archive.php文件(以及category-whats-new.php)都具有:
<?php
if ( have_posts() ) : ?>
<?php
$args = array(
'post_type' => 'any',
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => 'whats-new',
),
),
'date_query' => array(
'year' => '2018',
'month' => date('m'),
)
);
$the_query = new WP_Query( $args );
/* Start the Loop */
while ($the_query -> have_posts()) : $the_query -> the_post();
get_template_part( 'template-parts/archives/whats-new-archives', 'page' );
endwhile;
endif; ?>
然后我的模板零件文件具有:
<div class="recent-all">
<div class="display-posts-archives">
<ul>
<?php
/* $args = array(
'post_type' => 'any',
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => 'whats-new',
),
),
);
$the_query = new WP_Query( $args ); */
?>
<?php /*while ($the_query -> have_posts()) : $the_query -> the_post();*/
if (have_posts()) {
$post_type = get_post_type( $post->ID );
$art_img = types_render_field("article-image", array("raw"=>"true"));
$doc_img = types_render_field("document-image", array("raw"=>"true"));
?>
<li class="display-post-section">
<?php if($art_img != ''): echo(types_render_field("article-image", array(row =>true))); endif; ?>
<?php if($doc_img != ''): echo(types_render_field("document-image", array(row =>true))); endif; ?>
<a class="display-post-title" href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>
<span style="font-size: 9px; font-style:italic; color: red;"><?php echo $post_type?></span>
</li>
<?php
}
wp_reset_postdata();
?>
</ul>
但是我的输出仅显示类别中的所有帖子(很好,其中大多数),但没有按日期排序。有想法吗?