Skip to content

Instantly share code, notes, and snippets.

@designbuildtest
Created December 4, 2019 21:55
Show Gist options
  • Save designbuildtest/e9b167571fe7c8bf47b8ba826eb46756 to your computer and use it in GitHub Desktop.
Save designbuildtest/e9b167571fe7c8bf47b8ba826eb46756 to your computer and use it in GitHub Desktop.
Show sticky posts on the front page
/**
* Show sticky posts on the front page
*
* @link - https://wordpress.stackexchange.com/questions/202896/query-only-sticky-posts
*/
function edward_frontpage_sticky_posts() {
$stickies = get_option( 'sticky_posts' );
$features = new WP_Query(
array(
'post_type' => array( 'post', 'page' ),
'post__in' => $stickies,
'posts_per_page' => 12,
'ignore_sticky_posts' => 1,
'sort_column' => 'menu_order', // Important
'orderby' => 'menu_order',
'order' => 'ASC'
)
);
if ( $stickies && $features->have_posts() ) { ?>
<section class="page-content clear">
<?php while ( $features->have_posts() ) : $features->the_post(); ?>
<?php get_template_part( 'template-parts/content/content', get_post_format() ); ?>
<?php endwhile; ?>
</section><?php
wp_reset_postdata();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment