在 wp_query 上没有显示任何帖子

showing no posts on wp_query

我正在为 wordpress 设置自定义 post 类型,现在我正尝试在主页上显示 post。我想隐藏 posts 直到通过 has_tag 调用它们 我正在使用以下代码但它显示所有 posts.

$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>';
}
}

}  ?>