Skip to content

Instantly share code, notes, and snippets.

@paulgibbs
Forked from mjangda/shuffle-posts.php
Created May 23, 2013 21:41
Show Gist options
  • Save paulgibbs/5639647 to your computer and use it in GitHub Desktop.
Save paulgibbs/5639647 to your computer and use it in GitHub Desktop.
<?php $query = new WP_Query( array( 'posts_per_page' => 100, 'fields' => 'ids' ) ); ?>
<?php if ( $query->have_posts() ) :
$post_ids = $query->posts;
shuffle( $post_ids );
$post_ids = array_splice( $post_ids, 0, 12 );
foreach ( $post_ids as $post_id ) :
$post = get_post( $post_id );
setup_postdata( $post );
?>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
<?php endforeach; ?>
<?php endif; wp_reset_postdata(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment