Skip to content

Instantly share code, notes, and snippets.

@fernandofuly
Last active October 29, 2015 14:40
Show Gist options
  • Save fernandofuly/11a34211970ba50020de to your computer and use it in GitHub Desktop.
Save fernandofuly/11a34211970ba50020de to your computer and use it in GitHub Desktop.
Limit Number of Sticky Posts to Show
<?php
$sticky = get_option( 'sticky_posts' );
/* Sort the newest one at the top */
rsort( $sticky );
/* Get the 2 newest stickies (change 2 for a different number) */
$sticky = array_slice( $sticky, 0, 2 );
/* Query Post */
$args = array(
'post_type' => array( 'post' ),
'post__in' => $sticky,
'ignore_sticky_posts' => 2
);
query_posts($args);
?>
<!-- Output Html Here -->
<?php endif; wp_reset_query(); ?>
@tareqhassan
Copy link

where should I add this code to control the number of sticky posts on homepage?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment