WordPress Sticky Posts with Custom Post Types

So i need the ability to have a featured or “sticky” post in wordpress, and it occurred to me! Why not use the Sticky Posts facility, but after doing a bit of reading it seems that WordPress decided to not include support for it in latest releases and they don’t seem to be pushing any solution for future releases.

Now that leaves me in a predicament i wish to have the ability to have a featured post or custom post without using a category of such.

Read More

I’ve also seen a few people state they have hacked wordpress with possibly a function to add the ability of sticky posts to custom post types, shame they didn’t share the source!

How would this be done?

Related posts

Leave a Reply

5 comments

  1. You can do it with a custom field (post_meta) on the custom post type. Then fire a custom query that selects for the meta_value:

    $args = array('post_type' => 'my_custom_post_type', 'post_status' => 'publish', 'meta_query' => array('relation' => 'AND', array('key' => 'is_sticky', 'value' => '1', 'compare' => '=', 'type' => 'CHAR')));

    $sticky_posts = new WP_Query($args);

    Should return an array of published posts of post_type: my_custom_post_type that have the sticky flag set.

    Although I haven’t tested the above code, I’m doing something similar and it works fine.

  2. You can save a custom meta with the name of “sticky” and add it the value “on” when the post is sticky. That can be done with a custom metabox and a checkbox.

    WordPress will automatically add the word “Sticky” on the backend posts listing table

    You can retrieve a loop with your sticky custom posts by adding the values ‘meta_key’ => ‘sticky’ and ‘meta_value’ => ‘on’ to the args of your query