jcadima
8/21/2015 - 2:43 PM

Exclude Sticky Posts from Main Posts Index

Exclude Sticky Posts from Main Posts Index

reference:
https://wordpress.org/support/topic/how-can-i-exclude-sticky-post-from-custom-loop


<div id="random-posts">
<?php
$args = array(
'posts_per_page' => 4,
'orderby' => 'rand',
'post__not_in' => get_option( 'sticky_posts' )
);
$my_query = new WP_Query($args);
while ($my_query->have_posts()) : $my_query->the_post();
?>

  [SOME STUFF]

</div><!-- #random-posts -->

<?php endwhile; ?>
<?php wp_reset_postdata(); ?>