-
-
Save cristianstan/4612ec61eb5a91b2b48f8d2c8f8a0071 to your computer and use it in GitHub Desktop.
Create a WordPress While Loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Create a WordPress While Loop | |
-------------------------------------------------- */ | |
$wordpress_loop_argument = array( | |
'post_type' => 'custom_post_type', | |
'posts_per_page' => -1, | |
'orderby' => 'date', | |
'order' => 'ASC' | |
); | |
$wordpress_loop = new WP_Query( $wordpress_loop_argument ); | |
if( $wordpress_loop->have_posts() ) { | |
while ( $wordpress_loop->have_posts() ) : $wordpress_loop->the_post(); | |
echo '<div>'; | |
echo '<h2>'. get_the_title() .'</h2>'; | |
echo '<p>'. get_the_excerpt() .'</p>'; | |
echo '<a href="'. get_permalink() .'" title="'. get_the_excerpt() .'">Read More</a></p>'; | |
echo '</div>'; | |
endwhile; | |
wp_reset_query(); // Restore global post data stomped by the_post(). | |
} else { | |
// Nothing Found | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment