[英]showing no posts on wp_query
我正在为wordpress设置自定义帖子类型,现在我试图在首页上显示帖子。 我想隐藏帖子,直到通过has_tag调用它们为止,我正在使用以下代码,但是它显示了所有帖子。
$args = array( 'post_type' => 'homepage', 'posts_per_page' => -1 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) :
$loop->the_post();
echo '<div class="entry-content">';
the_content();
echo '</div>';
endwhile;
因此,我可以使用以下代码来完成此任务。
<?php
$args = array(
'post_type' => 'homepage',
);
$the_query = new WP_Query( $args ); ?>
<?php
// The Loop
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
if (has_tag('footer')) {
echo '<li>' . get_the_title() . '</li>';
}
}
echo '</ul>';
} rewind_posts();
// The Loop
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
if (has_tag('cta')) {
echo '<div class="cta-style">' . get_the_title() . '</div>';
}
}
} ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.