How to Add Sticky Posts in WordPress Custom Post Type Archives

Recently one of our users asked us if it was possible to add sticky posts to custom post type archives. By default, WordPress has the sticky functionality available for posts, but not for other post types. In this article we will show you how to add sticky posts in WordPress custom post type archives. Before we move forward, you would probably want to learn how to create custom post types in WordPress.

Adding Sticky Posts in Custom Post Types

First thing you need to do is install and activate the Sticky Custom Post Types plugin. After activating the plugin, go to Settings » Reading and scroll down to the section Sticky Custom Post Types. Next, you need to choose the custom post types where you want Stick This option to be enabled.

Now what we have done here is that we have added sticky posts feature to our custom post types. Sticky posts in custom post types will be displayed on the front page just like regular sticky posts.

The problem is that by default WordPress only shows sticky posts on the home page. It does not show sticky posts on archive pages.

Displaying Sticky Posts in Custom Post Type Archives

Lets assume that you have a custom post type for Movie Reviews with sticky posts enabled using the plugin we have mentioned above. Now you want your sticky posts in movie reviews post types to be displayed differently and on top of non-sticky regular movie reviews. Like this:

To achieve this goal, first thing you need is an archive template for your custom post type like this: archive-post-type.php. Learn how to create custom post type archive page. For example, if you have a custom post type movie-reviews then your archive page template should be archive-movie-reviews.php. If you do not have a template, create one. Simply copy the contents of archive.php in your theme’s directory and paste them into a new file archive-your-post-type.php.

The next step is to add this code in your theme’s functions.php file:

Tables can't be imported directly. Please insert an image of your table which can be found here.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63    

The above code would move your sticky posts to the top, and if your theme is using post_class() function, then it would add sticky in the post class.

You can style your sticky posts by using .sticky class in your stylesheet. Example:

Tables can't be imported directly. Please insert an image of your table which can be found here.

1 2 3 4 5 6

We hope this article helped you add sticky posts in custom post type archives.