• Hi there, I love how your plugin makes the stiky feature usable exactly in the same way as the default one for the normal posts. Congrats!

    I’ve been having trouble getting the sticky custom posts to show first on their archive. I’ve tried this but it only makes the sticky posts in a single page in the pagination show first. So if I have ‘posts_per_page’ => 4 and the only 5th post is a sticky one, it won’t be shown on the first page.
    Do you have a way to solve that and still keep pagination working?
    Thanks!
    Ricardo

    https://www.ads-software.com/plugins/seamless-sticky-custom-post-types/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author jaschaephraim

    (@jaschaephraim)

    The code in the article you linked queries some posts, then compares them to the list of sticky posts to put those at the top. So if you only query 4 posts per page, that 5th one will never be returned by the query and found to be a sticky post.

    There are more than one ways to solve this. Off the top of my head, I think the most efficient would be to query all of the sticky posts with the right post type, stick them at the beginning of the list, and then exclude them from your paged query.

    Thread Starter ricardjorg

    (@ricardjorg)

    Hi there, thanks for your reply.
    I’ll try your solution. It seems to require two loops, one for the sticky posts and another for the other ones. How do I make pagination work? Do I just run the second loop if the number of posts in the page wasn’t filled? And that way I can save the paged for only the current loop. And if in each page, the sticky loop returns no posts, I run the next loop and use the paged variable there..
    Wow, this seems more complicated than it should ??
    I’ll see what happens and post it here.
    Thanks!

    I’m also having the same issue – the plugin is working superbly for the Front Page but I’d like Sticky Posts also to appear at the top of the Archive Pages – having a separate loop will break the pagination.

    I’d be interested if you find any solutions!

    Plugin Author jaschaephraim

    (@jaschaephraim)

    Hey there. All this plugin does is add the native UI to mark custom posts as sticky, which means that their id’s will be stored and returned by the option get_option( 'sticky_posts' ).

    Beyond that, how to handle those id’s is up to you. As I mentioned above, you can do a query of just those post id’s without interfering with the main loop, check their post type, and spit them out before your regular paginated posts.

    There’s plenty online that will help you achieve this, but these details are beyond the scope of this plugin.

    Good luck ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Showing stiky custom post types first in loop’ is closed to new replies.