[Resolved] Sticky post not working

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Sticky post not working

  • This topic has 7 replies, 3 voices, and was last updated 2 months ago by Tom.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #20125
    Alexander
    Participant

    Hi,

    I got a carousel on my frontpage which displays 5 posts, but I want to be able to sticky a post as first post in the carousel, even if it would normally not be in the first 5 posts (e.g. because it’s older).
    The list queries a category the posts are in, in this category are currently 6 posts and I’m trying to sticky the 6th (older) post that’s currently not displayed.

    I checked the Stick to frontpage box, and made sure the Ignore sticky is unchecked, but it’s not showing up in the list – at all.

    Is this the expected behaviour? Or am I doing something wrong?

    Thanks!

    #20218
    David Beckwith
    Participant

    Hi there,

    Its working on my test site – do you have a link where we can see the issue?

    #20239
    Alexander
    Participant

    Hi,

    I doubt there’s anything you can see on the frontend; can I send you the details in private? I can even share the backend so you can take a closer look.
    Thanks!

    #20241
    Alexander
    Participant

    I dove into it a bit more, sorry for the double post.

    The culprit seems to be the is_home function in the WP_Query class: https://developer.wordpress.org/reference/classes/wp_query/is_home/
    This returns false, if I manually set it to true in the class, it does work.

    I’m using a static (but completely empty) frontpage of which the content is set by using the GP Premium Elements module (I insert multiple shortcodes using the generate_before_main_content hook on the static frontpage).

    Is there any way to ‘fix’ this?

    #20244
    Alexander
    Participant

    Third post’s a charm (really would like an edit button around here), the issue about the is_home thing remains, but I discovered the sticky post thing is category independent. I got several show post lists on my frontpage, but if I force the sticky posts feature the same post is shown in all lists, even if they don’t match the category I used for the list.

    This is to spec / expected behavior, but does mean I need to find a completely different solution regardless of the is_home function.

    #20351
    Tom
    Keymaster

    Hi there,

    What are you doing with is_home(), exactly?

    #20398
    Alexander
    Participant

    Hi Tom!

    I tried getting sticky posts to work in several post lists (carousels) on my static frontpage, and discovered it would disregard sticky posts because the WP Query class did not consider my frontpage to be the homepage (i.e. is_home() returned false).

    Upon forcing is_home() returning true (by momentarily adjusting the source of the WP Query class) the sticky posts were included in the list of posts, but then I found out the sticky posts feature works differently than I expected as the same sticky post was included in all post lists (even if it did not match the query/filter of the post list, e.g. category or tag).

    In the end I wrote some custom code that uses the the_posts filter to include sticky posts (that do match the category/tag/etc).

    I’ll mark the topic as resolved

    #20444
    Tom
    Keymaster

    Glad you got it sorted 🙂

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.