Created
December 4, 2019 21:55
-
-
Save designbuildtest/e9b167571fe7c8bf47b8ba826eb46756 to your computer and use it in GitHub Desktop.
Show sticky posts on the front page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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