簡體   English   中英

在wp_query上沒有顯示任何帖子

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM