0

I want to display only the sticky posts on my front page. Right now it's possible to do a setting where the sticky posts are displayed at the top followed by the rest of the posts. I don't want to rest of the posts to show up, so how do I make sure only the sticky posts are shown?

Thank you!

0

WordPress saves sticky posts inside the option named sticky_posts. You can retrieve them via get_option('sticky_posts').

With that knowledge it is possible to change the query to only query for sticky posts, you usually do so via the pre_get_posts hook.

add_action('pre_get_posts', 'WPSE_home_only_stickies');
function WPSE_home_only_stickies($query) {
    // only run for homepage & main query
    if ($query->is_home() && $query->is_main_query()) {
        $sticky_posts = get_option('sticky_posts');
        $query->set('post__in', $sticky_posts);
    }
}
-1

Try below steps

  1. Log into your WordPress admin panel.
  2. Look to the left hand sidebar menu and click the Settings option.
  3. From the expanded menu, click on the Reading option.
  4. You are brought to the Reading Settings page. From here, locate the Front page displays section and select the radio button for A static page (select below) .
  5. Next, select the page you want as your front page from the Front page:dropdown.
  6. Finally, set the Posts page: dropdown to --Select--. This effectively removes it from displaying on your site.
  7. Click on the Save Changes button to activate the new setup.

Hope this helps.

  • Why would this help? – kero Sep 27 '18 at 12:10
  • These would not display the default post – Krishna Joshi Sep 27 '18 at 12:12
  • 1
    But OP wants to display the sticky posts. Your solution would turn the page back to a regular page, displaying no posts at all – kero Sep 27 '18 at 12:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.