Skip to content

Instantly share code, notes, and snippets.

@jlittlejohn
Created September 11, 2012 23:15
Show Gist options
  • Save jlittlejohn/3702914 to your computer and use it in GitHub Desktop.
Save jlittlejohn/3702914 to your computer and use it in GitHub Desktop.
WP: Loop with get_posts()
<!-- Used to get an array of posts -->
<?php global $post; // required
$args = array(
'posts_per_page' => 5,
'numberposts' => 5,
'offset' => 0,
'category' => '',
'orderby' => 'post_date',
'order' => 'DESC',
'include' => '',
'exclude' => '',
'meta_key' => '',
'meta_value' => '',
'post_type' => 'post',
'post_mime_type' => '',
'post_parent' => '',
'post_status' => 'publish',
'suppress_filters' => true
); // Default arguments
$custom_posts = get_posts($args);
foreach($custom_posts as $post) : setup_postdata($post); ?>
<!-- code -->
<?php endforeach; ?>
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment