Skip to content

Instantly share code, notes, and snippets.

@Irfan-Ansari
Forked from mjangda/shuffle-posts.php
Created March 12, 2014 11:41
Show Gist options
  • Save Irfan-Ansari/9505239 to your computer and use it in GitHub Desktop.
Save Irfan-Ansari/9505239 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