Last active
November 10, 2016 19:15
-
-
Save joedajigalo/29c81285f5de15e3ba2e to your computer and use it in GitHub Desktop.
Create a WordPress Foreach Loop
This file contains hidden or 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 Foreach Loop | |
| -------------------------------------------------- */ | |
| $wordpress_loop_argument = array( | |
| 'post_type' => 'custom_post_type', | |
| 'posts_per_page' => -1, | |
| 'orderby' => 'date', | |
| 'order' => 'ASC' | |
| ); | |
| $wordpress_loop = get_posts( $wordpress_loop_argument ); | |
| foreach ( $wordpress_loop as $post ) : setup_postdata( $post ); | |
| echo '<article>'; | |
| echo '<h2>'. get_the_title() .'</h2>'; | |
| echo '<p>'. get_the_excerpt() .'</p>'; | |
| echo '<a href="'. get_permalink() .'" title="'. get_the_title() .'">Read More</a></p>'; | |
| echo '</article>'; | |
| endforeach; | |
| wp_reset_postdata(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment