---
description: >-
  https://wordpress.stackexchange.com/questions/104127/display-all-sticky-post-before-regular-post
---

# Display All Sticky Post Before Regular Post (ok)

![](https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWPtKFbhw0XehxVuoiZ%2F-Mk1S56nCYMJObmWYFmi%2F-Mk1SCjfujatD55tv2KU%2FScreenshot_1.png?alt=media\&token=a4cd3a44-c0f0-4d15-be67-b3f5d5bb9ee5)

![](https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWPtKFbhw0XehxVuoiZ%2F-Mk1S56nCYMJObmWYFmi%2F-Mk1SIgbV1ZWQiQ42Jx1%2FScreenshot_2.png?alt=media\&token=63db08a1-d7ab-4a48-861e-e1c3478c8c9b)

C:\xampp\htdocs\test1\wp-content\themes\twentytwentyone\index.php

```
<?php

get_header();?>
<?php if (is_home() && !is_front_page() && !empty(single_post_title('', false))): ?>
	<header class="page-header alignwide">
		<h1 class="page-title"><?php single_post_title();?></h1>
	</header><!-- .page-header -->
<?php endif;?>
<?php
echo "Is sticky post";
echo "<br/>";
$sticky = get_option('sticky_posts');
if (!empty($sticky)) {
  $args = array(
    'posts_per_page' => -1, //get all post
    'post__in'       => $sticky, //are they sticky post
  );
  // The Query
  $the_query = new WP_Query($args);
  while ($the_query->have_posts()) {
    $the_query->the_post();
    echo '<div>' . get_the_title() . '</div>';
    echo "<br/>";
  }
  wp_reset_query(); //reset the original WP_Query
}
echo "<br/>";
echo "Now get the not sticky post";
echo "<br/>";
$args2 = array(
  'posts_per_page' => -1, //get all post
  'post__not_in'   => $sticky, //are they NOT sticky post
);
// The Query
$the_query2 = new WP_Query($args2);
while ($the_query2->have_posts()) {
    $the_query2->the_post();
    echo '<div>' . get_the_title() . '</div>';
    echo "<br/>";
  }
  wp_reset_query(); //reset the original WP_Query
get_footer();
?>
```
