【发布时间】:2019-10-03 16:10:59
【问题描述】:
这里的代码可以工作,但是当我添加 category_name 或 tag_id(见下文)时 - 它不工作。
$query = new WP_Query( array( 'post_type' => 'project', 'posts_per_page' => 6 ) );
if ( $query->have_posts() ) : ?>
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<div>
<?php the_content(); ?>
<div style="clear:both; height: 0px; margin: -20px; padding: -20px;"> </div>
</div>
<?php endwhile; wp_reset_postdata(); ?>
<!-- show pagination here -->
<?php else : ?>
<!-- show 404 error here -->
<?php endif; ?>
一旦我添加了这个 -
$query = new WP_Query( array( 'post_type' => 'project', 'category_name' => 'featured', 'posts_per_page' => 6 ) );
或
$query = new WP_Query( array( 'post_type' => 'project', 'tag_id' => 34, 'posts_per_page' => 6 ) );
失败了。知道如何解决这个问题吗?
【问题讨论】:
标签: wordpress custom-post-type