Skip to content

Instantly share code, notes, and snippets.

@joedajigalo
Last active November 10, 2016 19:15
Show Gist options
  • Select an option

  • Save joedajigalo/29c81285f5de15e3ba2e to your computer and use it in GitHub Desktop.

Select an option

Save joedajigalo/29c81285f5de15e3ba2e to your computer and use it in GitHub Desktop.
Create a WordPress Foreach Loop
<?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