Sticky Custom Post Types WordPress Plugin

2011-08-20 5:47pm by Ann

I needed sticky custom post types for a client project but found out that WordPress doesn’t support this out of the box. Luckily it turned out to be pretty simple to add in that functionality with just a little bit of code… which I have turned into a plugin for everyone to use! YAY!

Installation/instructions:

1. Download the plugin from wordpress.org.

2. Upload sticky-custom-post-types.php to the /wp-content/plugins/ directory.

3. Select custom post types you want to enable with the sticky function on the ‘Settings → Reading’ page. Unless you’re using custom queries to display your sticky posts, you probably also want to check the option to display selected post types on the blog home.

4. When adding/editing a custom post type, check the “Stick this to the front page” checkbox if you want to stick that custom post to the front page.

And that’s it!

Unfortunately there’s no way to put the “Stick this…” checkbox in the same place as it is on the built-in “Posts” add/edit page (to do so would require modifying core code), but I think that having it display immediately is actually a lot more straightforward than having to click through the visibility setting edit link to get to it.

76 Responses to “Sticky Custom Post Types WordPress Plugin”

  1. Ashu says:

    Hello,
    I have created 3 custom post types for my client, now my client want sticky post feature for the custom post type. He wants to show custom post type post by tags, categories and sticky. Am using custom query code to display the post list by categories and tags but not able to get this sticky feature. So can you please help me out with code.
    Any help much appreciated.
    Thanks a lot in advance,
    Ashu

    • Ann says:

      $query = new WP_Query(array('post__in' => get_option('sticky_posts')));

      • Victor says:

        Hello! Great job with this plugin and thanks for sharing this code. I’m working with a client that would like to display a custom post type in a jquery slider. I have that working just fine, but now they would like to only display sticky’s from the same custom post type. So I installed your plugin and altered my code to this (part of the function):

        $globalSlider = new WP_Query ( array (
        ‘post_type’ => $postType,
        ‘category_name’ => $catName,
        ‘posts_per_page’ => $postNum,
        ‘post__in’ => get_option( ‘sticky_posts’ )
        ));

        I checked a couple posts created with the custom post type it is still displaying non-sticky posts. Any ideas or suggestions would be really appreciated. Thanks.

  2. thomas says:

    Hi, this is a great plugin. One question how do I stop the custom post from also displaying in the loop? Im trying to use post__not_in but its not working
    code:
    $wp_query = new WP_Query();
    $wp_query->query( array( ‘post__not_in’ => get_option( ‘sticky_posts’ ) ));

    • Ann says:

      You need to set the ‘post_type’ argument to ‘post’ in your query. I just checked in a new version of the plugin that will optionally enable adding checked custom post types to the home loop (sticky posts are enabled only when is_home and on the first page) so please update and let me know if you’re still having problems.

  3. Tim says:

    Hi there,
    Plugin is great worked fine.. ..and then boom. An update to another plugin ‘Advanced Custom Fields’ (http://wordpress.org/extend/plugins/advanced-custom-fields/) has knocked it out and loops involving sticky posts dont work at all.

    Now I know that issues with other plugins isnt your responsibility and I dont mind, I just wondered if there was any obvious reasons as to why they dont play together..

    ..But anyhow, plugin on its own works fine!

    Thanks.

    • Ann says:

      I can’t think of why that plugin would affect mine… However I did recently update my plugin and by default it won’t include custom post types (sticky and normal) in the home loop anymore unless you enable that setting. Could that be your issue?

    • Sean says:

      Hi Ann,
      Awesome Plugin, very simple and easy. :)

      I wanted to chime in here and mention I had an issue at first too. And my client has the plugin Advanced Custom Fields as well. They also use the Theme Insignio (http://themes.codehunk.me/insignio/ )

      They wanted the sticky feature for their Portfolio (Custom Post Type) display page. I installed your plugin, went to settings and selected the custom post type Portfolio and I also checked the Display on Home as well.
      First I checked the Portfolio page after making a Portfolio post sticky. WORKED perfect. Nice and easy. :)
      Then I checked the home page and it (your plugin + theme) added posts to the home page (in slider) even though I didn’t have them there before.
      So I unchecked the Display on Home and BAM! the site stopped loading the Home, or the Portfolio page completely. In fact it seemed to get stuck while the images were loading. ie. the spots where some javascript come in and show a pretty loading circle, but the loading circles never disappeared and the page just broke/stopped loading. In fact when viewing the Portfolio page only 3 posts start to display with image loading animations on each before it stopped loading the rest of the posts.

      I’m not sure if this is a conflict with the Advanced Custom Fields plugin or the Theme.

      My solution ended up being to just comment out the last line in your plugin:
      // add_filter(‘pre_get_posts’, ‘super_sticky_posts_filter’);

      Then the home page loaded correctly and the Portfolio page loads correctly AND I get to keep your plugin activated as well as the ACF plugin.

      Just a big thanks for this plugin and hope this helps others/future versions of this plugin. :)

      Peace,
      Sean

      • Ann says:

        Hi Sean,

        There shouldn’t be any conflicts between this plugin and the Advanced Custom Fields plugin. This sounds to me like a conflict with code in the theme… specifically post filters that the theme must add to the home page loop for the custom Portfolio post type display.

        I’m glad to hear that you were able to resolve the issue by removing this plugin’s post filter. However, instead of commenting out plugin source, I would suggest removing this plugin’s filter by adding the following code to your theme functions.php file:

        remove_filter(‘pre_get_posts’, ‘super_sticky_posts_filter’);

        Good luck with your site development and thanks for using my plugin!

        Ann

  4. Matt Jarvis says:

    Hi – thanks for this plug in, however with wordpress 3.1 and trying to list all posts in a custom post_type, it seems to interfere and bring in some very random results (not just stick posts). Was driving me a bit crazy as I couldn’t understand it, even using

    $show_query = new WP_Query( array (“post_type” => “sl_shows” , ‘ignore_sticky_posts’=> 1, ‘post_status’ => ‘publish’, ‘orderby’ => ‘title’, ‘order’ => ‘ASC’, ‘posts_per_page’ => 5 ) );

    brought in 2 other post_types (ignore_sticky_posts did seem to work, maybe there is some id overlap?)

    best wishes
    Matt

    • Ann says:

      Hey Matt, are you saying that your query is still bringing in random non-sticky posts of post types other than the one you specified? If so, are there any other filters that might be affecting query results? Did you try adding the suppress_filters parameter to your custom query?

  5. Vanessa says:

    Hi Ann, thanks for this plugin. Question: I created a custom post type and am displaying the posts via archive-posttype.php. It seems your plugin does not stick the posts in the archive page. Will your plugin work within an archive display? Thanks!

    • Ann says:

      Hi Vanessa, unfortunately the plugin doesn’t currently add sticky posts to the custom post type archive pages, although this function is something I would likely add down the line.

  6. Hi – nice plugin – works with the default WP frontpage default posts listing. Hoever I am having trouble getting it to work when I do a custom loop (of the Delight theme):

    
        $sticky = get_option('sticky_posts'); // my new code
        $args=array(
        'post__in'  => $sticky, // my new code
        'ignore_sticky_posts' => 1, // my new code
        'gallery'  => $cat_selected,
        'post_type' => 'portfolio',
        'posts_per_page' => $posts_per_page,
        'paged' => $paged
      );
      $my_query = null;
      $my_query = new WP_Query($args);
      $i=0; while ( $my_query->have_posts() ) : $my_query->the_post();
    

    any suggestions?
    many thanks,
    Mike

    • Ann says:

      If you look at wp-includes/query.php line 2683, you’ll see that all the logic for splicing sticky posts in at the top and removing them from the flow is only going to be run if is_home is true. So you could either set the home flag or copy the logic from the core to get your custom query to return the posts you’re looking for. Neither are really great solutions for sticky posts IMO, so perhaps the right thing to do would be to submit a suggestion to trac to expand on this limitation.

  7. Toine Kamps says:

    Hi Ann,

    Thanks for this plugin, I was looking for this!
    I was experiencing the same problems as Matt Jarvis, on a completely different page in a different loop suddenly other custom post types were showing up, even when post_type was set to ‘post’ like this:
    ‘post_type’ => ‘post’

    The suppress filters parameter in this loop did the trick though:
    ‘suppress_filters’ => true

    I discovered a second problem though if your’re using the very useful posts-to-posts plugin from scribu: http://scribu.net/wordpress/posts-to-posts

    If I want 2 out of my 6 custom post types to be enabled for sticky support on the homepage, I check these post types on the ‘Settings -> Reading’ page, as well as the ‘Display selected post type(s) on: home’.
    I discovered that the other 4 post types lose their connection from the posts-to-posts plugin if you do this, or at least they don’t show up anymore.

    If I check all 6 of the custom post types on the ‘Settings -> Reading’ page the problem is solved, but then anyone could make any of the custom posts sticky on the homepage. Is there are a fix for this?

    Thanks!

    • Ann says:

      Unfortunately I’m not familiar with that plugin… but I’m guessing that what you mean is that it’s already displaying custom post types you want on your home page, though not as sticky posts. Basically, I think the problem is that my plugin takes those backend settings and tells the home page to filter out all the custom post types that are unchecked… and it uses the same settings to determine which custom post types to add that sticky option checkbox to.

      To get around this, the easiest thing to do would probably be to disable my plugin’s home page posts filter and write your own. So in your functions.php file:

      
      function my_sticky_posts_filter($query) {
        if($query->is_home && !$query->get('suppress_filters')) {
          $post_types = get_post_types(array('_builtin' => false, 'public' => true), 'names');
          $query->set('post_type', $post_types);
        }
        return $query;
      }
      remove_filter('pre_get_posts', 'super_sticky_posts_filter');
      add_filter('pre_get_posts', 'my_sticky_posts_filter');
      

    • The ‘suppress_filters’ => true did the trick for me too!

      thanks

  8. Toine Kamps says:

    Thanks for you reply!
    Well, altough it’s a bit tricky that users can make any post type sticky now, I think I’ll stick to keeping the post_types checked for now.
    Setting that ‘suppress_filters’ is vital by the way, because it’s messing up almost all my other loops in my site.
    Cheers

  9. Igor says:

    Hello, Ann! Thank you for this clear plugin. I wonder if it’s possible or not, to get (with it’s help) a list of sticky posts of specific custom post type: not in the loop (where you can apply filter), but outside, for example in the sidebar.

    I use this common way:

    $sticky_ids = get_option(‘sticky_posts’);
    $sticky_posts = get_posts( ‘include’ => $sticky_ids )

    The problem is: there are ids of posts of all types, not only needed in every special case.

    • Ann says:

      Hi Igor,

      You should be able to specify the post types you want get_posts() to return. For example, say you just want to display two custom post types, “events” and “books”:

      
      $sticky_posts = get_posts(array(
           'post__in' => get_option('sticky_posts'),
           'post_type' => array('events', 'books')
           ));
      

  10. Antuan says:

    No funciona en WP 3.3.1

  11. Toine says:

    Hi again,
    Unfortunately your plugin is causing troubles with the plugin SlideDeck: http://www.slidedeck.com
    The slides are not showing up at all… I confirmed it’s caused by this plugin.
    Any ideas on how to fix this?
    Thanks!

  12. Toine says:

    To be more specific, it’s line 94 in your sticky-custom-post-types.php code:
    add_filter(‘pre_get_posts’, ‘super_sticky_posts_filter’);
    ‘pre_get_posts’ conflicts in someway….

    I really need both of these great plugins to work together :(

  13. Toine says:

    Hi Ann, thanks for getting back to me!
    Unfortunately that doesn’t change anything… It’s the following line:
    $query->set('post_type', $post_types);
    that messes everything up somehow (even my menus dissapear all of a sudden).
    How should my custom query look like when I remove your filter?
    Now it looks like this (it checks if there are any stickies otherwise it will show my latest post):

    $sticky = get_option(‘sticky_posts’); // Get sticky posts
    $tmp = array(‘post__in’ => $sticky, ‘post_status’ => ‘publish’); // Get published sticky posts
    $stickypublish = new WP_Query($tmp);
    $totalstickies = count($stickypublish); // Get total of published sticky posts

    $notsticky = get_posts(array(‘posts_per_page’ => 1)); // Get featured posts
    $total = count($notsticky); // Get total of featured posts

    if ($sticky) {   // If there are sticky posts
      $supress = false;
    } else { // If there are no sticky posts
      $supress = true;
    }
    $args = array(
      'suppress_filters' => $supress,
      'posts_per_page' => 1,
      'post__in'  => $sticky,
      'post_status' => 'publish',
      'ignore_sticky_posts' => 1
    );
    query_posts($args); // Show newest published sticky post  
    
    if (have_posts()) :
      while (have_posts() ) : the_post(); ?>
        // Display post
      <?php endwhile;
    endif;
    wp_reset_query(); ?>

    Any thoughts of what might go wrong?
    Thanks!

    • Ann says:

      Did you ever figure out these issues? Does the slidedeck plugin use custom post types for anything? Is something getting messed up on the blog home only or are other pages affected?

  14. Toine says:

    Hi Ann,
    Jup SlideDeck uses a custom post type for it’s slides, but almost al of the plugins do. Actually nothing got messed up, but the SlideDeck instances simply didn’t show up. In the end I think the problems were caused by the SlideDeck plugin itself.
    I ended up using a different plugin called ‘AnythingSlider’ http://wordpress.org/extend/plugins/anythingslider-for-wordpress/
    which works perfectly in combination with your plugin :)
    Thanks!

  15. Tom says:

    Hello,
    First, great plugin !
    The backoffice part is perfect.

    For the front, I have to write two custom queries (bad perf.) rather than patch with this : http://core.trac.wordpress.org/ticket/12702
    (and commented your plugin filter , ‘pre_get_post’)
    here is my loop query :

    $sticky = get_option(‘sticky_posts’);
    $shows = (int)get_option(‘force_home_display’);
    $args = array(
    ‘post_type’ => ‘product’,
    ‘post__in’ => $sticky,
    ‘posts_per_page’ => $shows
    );

    $loops_sticky = query_posts($args);
    // here I could count the size of first loop and redifine second loop count // something like $shows = $shows – sizeof($loops_sticky )
    $args_no_sticky = array(
    ‘post_type’ => ‘product’,
    ‘post__not_in’ => $sticky,
    ‘posts_per_page’ => $shows
    );
    $loops_no_sticky = query_posts($args_no_sticky);
    // need more if($loops_no_sticky) /else test
    $loops = array_merge($loops_sticky,$loops_no_sticky);
    // debug
    //print_r($loops);

    Note : I don’t understand why there is a else case, in the pre_get_posts filter
    else
    $query->set(‘post_type’, ‘post’);
    I think it could be suppressed to avoid a lot of issues (custom queries, ..)

    • Ann says:

      Hi Tom, thanks for commenting on my plugin!

      For stuff like sticky archive pages on the front end I’ve also done it that way myself with a couple of loops (I like to use the the_posts filter in my functions.php file so I can keep my template files clean). Last time I looked, the sticky posts code in query.php had a hard-coded check for is_home, but you could also copy and paste the code from there for your custom query.

      The way this plugin works is pretty simple — I just add in the checkbox backend ui on the edit page for custom post types so that they can be selectively added to the global sticky_posts array. The reason the else case in pre_get_posts is there is to filter out all the custom post types from the sticky posts array in the case where a person might not want to display those on the home page, but still might want to use the backend ui to set some custom posts to sticky (for custom loops or something).

  16. mike says:

    Hi Ann – this plug-in is great and does almost exactly what I need. The only thing is, when I activate it, it’s making ALL of my custom post types appear on my home page, not just the ones marked ‘sticky’. Is that intended?

    • Ann says:

      Yep. If you just want sticky custom posts to show, you can remove the pre_get_posts filter:

      remove_filter(‘pre_get_posts’, ‘super_sticky_posts_filter’);

      • mike says:

        thanks for the reply. I’m not quite sure I understand, though. I thought the point of the plugin was that it would only show posts which were selected as sticky, so why do i need to edit PHP to make it do that as opposed to showing all custom posts? if so, where would i find that line?

        • mike says:

          Hi Ann – nevermind, I figured it out. (I’m good at CSS, but a total noob at PHP.) Works perfectly now. Not sure I understand why the intended behavior would be to display posts that are not marked as sticky, but no worries now – this plug-in is a real life-saver and should probably have been part of the actual WP release.

          • Ann says:

            People will generally want to supplement their home page with custom post types both sticky and non, to be shown alongside regular posts. To have a mix of custom and regular post types at the top followed by regular posts only is less in line with most use cases.

            You can actually add the remove_filter line to your theme’s functions.php file. This way you can leave the plugin code intact.

  17. Scott says:

    Hi,

    Thanks for such a handy plugin!
    I am having a small issue with it. The posts I mark as sticky appear at the top of the first page as expected but when navigating to page 2 of posts, they also appear at the top there. Is that intended? It would be great if they only appeared at the top of page 1.

    Thanks!

    • Ann says:

      Hi Scott,

      Hmm, that isn’t the way the plugin works on the default home loop… Are you using any custom loops or post filters in your theme, or using any other plugins that might be altering your home loop?

      • Scott says:

        Hey,

        Perfect time to reply! I just looked into it a bit more and it was probably coincidence because it wasn’t actually repeating them on page 2. Instead, they all naturally appeared at the top of page 2 and I assumed it was the plugin causing it but was just where they were in the loop.

        I figured when I set them to ‘sticky’ it would remove them from their ‘expected’ position and only show them at the top of page 1 (nowhere else) but instead they get shown twice (at the top of page 1 and once in the position they would appear had they not been made sticky).

        Unfortunately not ideal for what I need, but a great plugin none-the-less!

        • Ann says:

          I think something else might still be affecting the query… the way it works is the same way the WordPress home loop does, so sticky posts do get pulled out of the regular flow.

          • Geoff says:

            I’m having the same issue where the sticky post is not being removed from the regular flow. I am using a custom loop for the home page and AJAX to load more posts (from /page/#).

  18. Bloody says:

    Hello Ann,
    First, great plugin ! I really need such a good plugin for my project.

    Before I discovered your plugin, I used this query without the sticky option:

    have_posts()) : $my_query->the_post();?>

    and now I use this Query :
    get_option(‘sticky_posts’),
    ‘post_type’ => ‘galerie’,
    ‘post_statut’ => ‘publish’,
    ‘orderby’ => ‘date’,
    ‘order’ => ‘DESC’,
    ‘posts_per_page’ => 3,
    ));
    ?>

    But it don’t work.
    Could you tell me where I made a error.

    Thanks.

  19. Bloody says:

    Sorry,

    I’ve forgot my Code HTML tag in my last comment.

    Here my old query without sticky argument :
    <?php $my_query = new WP_Query($query_string.'post_type=galerie&orderby=desc&publish&order=desc&showposts=3'); while ($my_query->have_posts()) : $my_query->the_post();?>

    And now tne new one :

    
    <?php $query = new WP_Query(array(
          'post__in'    => get_option('sticky_posts'),
          'post_type'    => 'galerie',
          'post_statut'  => 'publish',                
          'orderby'     => 'date',
          'order'     => 'DESC',                
          'posts_per_page'=> 3,              
                                ));
     ?>    
    

    Ann could you tell me what is wrong in my new one ?
    Thanks !

    • Ann says:

      It looks like there is a typo in your query argument array… ‘post_status’ is misspelled. You might also try setting ‘suppress_filters’ to true.

  20. Bloody says:

    Thanks a lot Ann.
    You’re right. “post_status” was just misspelled.
    Your plugin is really great.
    Thanks !

  21. Carol says:

    Hi Ann. Thanks for an excellent plugin. It has been working great – except.. I’m trying to show all sticky post posts for my custom post type in random order – it seems to be ignoring the “random” part of the query. Here’s my code:

    $args = array( ‘post__in’ => get_option(‘sticky_posts’),’posts_per_page’=>-1 , ‘orderby’ => ‘rand’, ‘post_type’ => ‘mycustompost’ );

    Is there something obviously wrong with the query?

    • Ann says:

      Hi Carol,

      Do you have any other plugins active that might be overriding post order? I’d suggest setting suppress_filters to true and seeing if that fixes things.

      • Carol says:

        Thanks for your reply Ann. I figured out a solution – apparently I needed to force the use of rand() by inserting the following lines before my query

        function mam_posts_orderby ($orderby) {
        global $mam_global_orderby;
        if ($mam_global_orderby) $orderby = $mam_global_orderby;
        return $orderby;
        }
        add_filter(‘posts_orderby’,’mam_posts_orderby’);
        global $mam_global_orderby;
        $mam_global_orderby = ‘rand()';

        That did the trick!

  22. Erik says:

    Amazing plugin, thank you for your efforts! I have a question regarding how to properly query for a sticky CPT within a subloop using wp_query.

    I’m running a 2 nested loops (2 wp_queries within the main wp_query) , one to display a the most recent blog post (works good) and another to show a sticky CPT-post. But my sub loop for my sticky CPT-post does not seem to populate the wp_query->posts index! Here’s my nested query to bring up a sticky CPT:

    /*First, I display most recent blog post here*/
    /*And now I want to display a sticky-CPT ‘projekt’ */

    $original_query = $wp_query;
    $wp_query = null;
    $wp_query = new WP_Query(array(
    ‘post_type’ => ‘projekt’,
    ‘ignore_sticky_posts’ => 1,
    ‘post__in’ => get_option(‘sticky_posts’),
    ‘nopaging’ => true,
    ‘posts_per_page’ => -1
    ));
    if (have_posts()) :
    while (have_posts()) : the_post();
    the_title();
    the_excerpt();
    endwhile;
    else:
    echo ‘no posts found!';
    endif;
    $wp_query = null;
    $wp_query = $original_query;
    wp_reset_postdata();

    The wp_query->query->post__in array contains the post ID of the sticky CPT-post. But shouldn’t my query also populate the wp_query->posts index so that I can use the regular while have_posts-loop and its tags? I’m following the example given here to reset postdata: http://codex.wordpress.org/Function_Reference/wp_reset_postdata

    Advice much appreciated!

  23. David says:

    Hi. Thanks for making this plugin. I’m using it on my new site, with ThemeZilla’s Scope theme ( http://demo.themezilla.com/?theme=scope&ref=tf ). There’s a blog, which has it’s own main page, and then a custom type called portfolios that has its own grid-style main page. The latest four portfolio grids appear on the home page. I used your plugin to choose specific portfolios for the home page instead; however, doing so had the side-effect of putting all of the portfolio entries in the blog, and all the blog entries in the portfolio grid. How can I prevent this co-mingling?

  24. ben c says:

    Hi,

    Is there anyway to stop sticky posts being stuck to the top of RSS feeds?

    Cheers
    Ben

  25. Hey Ann,

    This is quite a helpful plugin. :)

    I work for WordPress.com VIP and one of our clients requested this type of functionality, so I did a code review of your plugin. Along the way I found a few bugs in your plugin:

    First it overwrites the existing value of post_type instead of appending to it. So if someone does something like this (which would display a listing of Pages on the blog homepage):

    add_action( 'pre_get_posts', 'modify_main_query_post_type', 5 );
    function modify_main_query_post_type( $query ) {
      if ( $query->is_main_query() && $query->is_home() ) {
        $query->set( 'post_type', array( 'page' ) );
      }
    }

    Then your plugin changes that to show posts plus any custom post types that have been opted into, totally discarding the previous value.

    Second, it affects queries that are in widgets in your sidebar and other places because it doesn’t make sure that it’s only affecting the main post query.

    You can find a version of your plugin with these bugs fixed along with a few minor improvements (escaping attributes for example) here:

    https://gist.github.com/3411579

    Additionally I’ve also made a version that cleans up the plugin to match the WordPress coding standards and that can be found here (most of the changes were whitespace related):

    https://gist.github.com/3411587

    Hopefully you find these useful. :)

    • Hmm, I manually escaped the HTML entities in my code snippet but it seems they got automatically escaped as well.

      • Toine Kamps says:

        Hi Alex,

        Thanks for your update! Great work!
        I was wundering how I can achieve the following situation because I don’t think it’s possible anymore with this revamp;
        I have several custom post types and I gave some of them the ability to sticky them to the homepage, what if I have let’s say 4 sticky posts, all of them from different custom post types and I only want to display the newest one, so just 1 instead of 4?
        No matter what I try, it displays all 4 of them. ‘posts_per_page’ obviously does not work… Any ideas? This is my code:

        $sticky = get_option('sticky_posts'); // Get sticky posts
        $totalstickies = count($sticky); // Get total of published sticky posts
        rsort( $sticky ); // Resort sticky posts, newest at the top
        $firststicky = array_slice($sticky, 0, 1); // Get 1st sticky post
        
        $args = array(
          'posts_per_page'     => 1,
          'post__in'        => $firststicky,
        );
        query_posts($args);
        
        // this displays 4 posts
        if (have_posts()) : 
          while (have_posts() ) : the_post();
            the_title();
          endwhile;
        endif;

        Any help is welcome!
        Thanks

    • Ann says:

      Hey Alex,

      Thanks for providing those fixes/improvements! I pretty much wrote this plugin specifically for a very limited use case, but your mods definitely make the filter more flexible out of the box. Frankly I didn’t even know about the is_main_query function introduced in 3.3… very handy! Also appreciate the formatting updates to make it conform with the coding standard guidelines. Will be sure to get these updates into the plugin repository soon.

  26. Nicolas says:

    Hi,
    Following this topic in wordpress: http://wordpress.org/support/topic/menu-empty-when-polylang-and-sticky-custom-post-types-plugins-are-activated?replies=11#post-3130175 I think you should update your plugin accordingly to avoid any further issues with it.

    Cheers
    Nicolas.

  27. Jason says:

    Hey Ann,
    Great plugin – it’s ‘almost’ fast tracked an issue with one of my client sites.
    It’s a WooThemes theme I’m customising, it has an area on the homepage where it can display mini features (which are custom post types).
    http://www.woothemes.com/products/simplicity/
    To display these on the homepage they have to be enabled under theme options, with a number selected to be displayed (in my case it’s 3).
    The problem I have (which you may know a workaround for) is if I select 3 as sticky – it displays them on the homepage, but also 3 others.
    If I select 1 (under the WooThemes theme options) it will display my 3 sticky one’s & only 1 other (follow)?
    So somehow I need to let WP know that it should only display my sticky one’s (or somehow still enable the homepage display of the mini features – but have the selected number = 0.
    I’ve asked WooThemes support if this is possible, but I thought I’d touch base with you also in case you know of a work around.
    I’ll post back here if WooThemes come back to me with their own fix.
    Thanks again!
    Jas

    • Jason says:

      Ok, I think I’m pretty close to answering my own question.
      This is the code;

      ID, ‘mini_excerpt’, true ) );
      $button = get_post_meta( $post->ID, ‘mini_readmore’, true );
      $post_class = ‘post block';

      if ( $count % $mini_features_count == 0 ) { $post_class .= ‘ last'; }
      ?>

      If I modify the above to include the ‘is_sticky’ conditional – then I should be sorted?
      Any pointers on where/how I’d do that?
      Thanks!
      Jas

  28. Toine Kamps says:

    Hi there,
    Any reports that the plugin breaks in WordPress 3.5?
    I can’t get my code to work anymore in the new wordpress…

  29. Paul Biron says:

    thanx for this, fit a big need I have.

    Have you considered adding a “Sticky” checkbox to Quick Edit?

    That would be a big help, both from a usability standpoint and it would also fix what I think is a bug: if I set a custom post as sticky (in the Edit screen) and then do a Quick Edit on that post, that post is no longer sticky.

    I’m not sure if it is even possible (in a general sense) to add such a checkbox to Quick Edit, since the only way I know to add fields to Quick Edit is with the ‘quick_edit_custom_box’ action, which only fires for columns added with ‘manage_${post_type}_posts_columns’ filter and we really don’t want to have to add a Sticky column for every custom post type that we want to be sticky.

    For the use I currently have for sticky custom post types, having a Sticky column is OK (since I can hide it in Screen Options). Therefore, I’ve modified your plugin code by changing ‘super_sticky_add_meta_box()’ as follows:

    function super_sticky_add_meta_box() {
    if( ! current_user_can( ‘edit_others_posts’ ) )
    return;

    foreach( super_sticky_post_types() as $post_type ) {
    add_meta_box( ‘super_sticky_meta’, __( ‘Sticky’ ), ‘super_sticky_meta’, $post_type, ‘side’, ‘high’ );
    //pvb: add the Sticky column to “All ${post_type}” screens
    //pvb: not bothering to add ‘manage_${post_type}_posts_custom_column’ action since
    //pvb: I plan on hiding the column anyway
    add_filter (“manage_${post_type}_posts_columns”, create_function (‘$cols’, ‘$cols["sticky"] = “Sticky” ; return ($cols) ;’)) ;
    }
    }

    and adding the following code add the end of sticky-custom-post-types.php:

    /*
    * pvb: everything below here has been added by me and any errors are my responsibility,
    * and not plugin’s original author
    */

    /*
    * this adds the sticky checkbox to Quick Edit
    */
    function
    quickedit_posts_custom_box ($col, $type)
    {
    if (!(‘sticky’ == $col && in_array ($type, super_sticky_post_types ()))) {
    return ;
    }
    ?>

    Make this post sticky

    <?php

    return ;
    }
    add_action ('quick_edit_custom_box', 'quickedit_posts_custom_box', 10, 2) ;

    /*
    * this (and the associated js/custom_quick_edit.js) sets the current value of
    * the Sticky checkbox added with quicedit_posts_custom_box()
    */
    function
    admin_footer_edit ()
    {
    if (isset ($_GET['post_type']) && in_array ($_GET['post_type'], super_sticky_post_types ())) {
    echo '';
    }

    return ;
    }
    add_action (‘admin_footer-edit.php’, ‘admin_footer_edit’, 11) ;

    The js/custom_quick_edit.js file contains the following:

    /*
    * sets the checked attribute on the Sticky checkbox according to
    * whether the custom post is currently sticky or not
    */
    function
    quickEditSticky ()
    {
    var _edit = inlineEditPost.edit ;
    inlineEditPost.edit = function (id) {
    var args = [].slice.call (arguments) ;
    _edit.apply (this, args) ;

    if (typeof (id) == ‘object’) {
    id = this.getId (id) ;
    }
    if (this.type == ‘post’) {
    // editRow is the quick-edit row, containing the inputs that need to be updated
    var editRow = jQuery (‘#edit-‘ + id) ;
    // postRow is the row shown when the custom post isn’t being edited, which also holds the existing values.
    var postRow = jQuery (‘#post-‘ + id) ;

    // get the current Sticky value
    var sticky = jQuery (‘div.sticky’, postRow).text () ;

    // set the value in the quick-editor
    if (sticky) {
    jQuery (‘:input[name="sticky"]‘, editRow).attr (‘checked’, ‘checked’) ;
    }
    }
    } ;

    return ;
    }
    // Another way of ensuring inlineEditPost.edit isn’t patched until it’s defined
    if (inlineEditPost) {
    quickEditSticky () ;
    }
    else {
    jQuery (quickEditSticky) ;
    }

    [I apologize if the above code doesn't format correctly], you can grab my modified version from http://sparrow-hawk.org/sticky-custom-post-types-pvb.zip to see the edits]

    If you know of a way to add a Sticky checkbox to Quick Edit without adding the Sticky column, I would love to see it added to a future version of this plugin.

  30. Scott says:

    I was recommended to use your plugin by the maker of my wordpress skin/site. I’m trying to get a video to remain on the front page of my site. I followed the instructions above and it didn’t work. Does this plugin only work for posts? I have a video page and every time I upload a video, the latest one displays on my home page. Please let me know if you can think of a way to fix this.

    Scott

  31. Sarah says:

    Hi Ann!

    I’m trying to add the sticky posts to the top of the posts on the index.php of the twenty twelve theme while still having the recent posts flow through that page. Would you know the code to be able to do this?

  32. Morteza says:

    Hi Ann,
    First, thanks for your great plugin ! works fine for me without problem.

    I’m making a classified theme for one of my clients and I had to define some Custom Post Types and some Meta Boxes inside. I need to put Sticky Checkbox into the previously added Meta Box not a separate which now is in.
    How can I do this?

    Thanks in advance

    Morteza

  33. Nicole says:

    Hi there,

    We build our site on word press. We have a featured webisode on our home page and Sticky to switch out the webisodes in the main player. Lately, I uncheck the box for one episode, check it for the new one, and the switch never happens. Any idea why this might be, and how I can fix it? Thanks!

  34. TecNQ says:

    Hi. I installed this plugin straight out of the box, activated the tickbox for our custom posts area, and I see the option now to enable Sticky. However, when I update the post, I get … “You are not allowed to edit posts as this user”, but I am the Admin and I have full roles and permissions set. Is there something missing? Thanks

  35. Daniel says:

    Hello,
    I installed the plugin on my new site (not launched yet) and set my CPTs as sticky.
    However, the CPTs are not displayed on the home page slider.

    I am using Pinboard theme. And, I tried with CPTs created using Custom Post Types UI and also with CPTs created by adding codes to the functions.php.

    Can you help me?
    Thanx.

    • JEns says:

      Hey Daniel,

      same problem here with Pinboard and The Event Calendar.
      Could you solve the problem?

      Best Jens

Leave a Reply

Current day month ye@r *