I am setting up a custom post type for wordpress and now i'm trying to display the posts on the homepage. I would like to hide the posts until they are called via has_tag i'm using the following code but it displays all of the 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;
So I was able to get this accomplished by using the following code.
<?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>';
}
}
} ?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.