Get sticky post from category?

Use the below code in the mainpage template to show the sticky posts.

<?php 
$args = array(
    'cat'            => 42,
    'posts_per_page' => 10,
    'post__in'       => get_option( 'sticky_posts' ),
);
// The Query
$the_query = new WP_Query( $args );

// The Loop
while ( $the_query->have_posts() ) {
    $the_query->the_post();
    echo '<li>' . get_the_title() . '</li>';
}

The above will print the title of the sticky posts

Leave a Comment