It is unfortunately that WordPress doesn’t have parameter to sort based on sticky status. To show them on top of a list, we need to query them separately then merge with other normal post list.

$sticky_args = array( 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => 10, 'offset' => 0, 'include_sticky_posts' => true, 'include' => implode(',', get_option('sticky_posts')), ); $args = array( 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => 10, 'offset' => 0, 'include_sticky_posts' => false, ); $sticky_posts = get_posts($sticky_args); $posts = get_posts($args); $all_posts = array_merge($sticky_posts, $posts); foreach ( $all_posts as $p ){ //show data }
include_sticky_posts
parameter determines whether the query includes sticky posts in result or not. So, for the sticky post list, it must be set to true, and for the normal post list, it should be false to avoid query the same posts on 2 lists.
include
parameter determines a list of posts to be included in result. We get those sticky posts’ IDs from option table with get_option('sticky_posts')
.