Home › Forums › Pro Support › Sticky post not working
- This topic has 7 replies, 3 voices, and was last updated 3 years, 2 months ago by
Tom.
-
AuthorPosts
-
September 27, 2020 at 9:32 am #20125
Alexander
ParticipantHi,
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!
September 28, 2020 at 9:46 am #20218David Beckwith
ParticipantHi there,
Its working on my test site – do you have a link where we can see the issue?
September 28, 2020 at 11:31 am #20239Alexander
ParticipantHi,
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!September 28, 2020 at 11:51 am #20241Alexander
ParticipantI 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?
September 28, 2020 at 12:11 pm #20244Alexander
ParticipantThird 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.
September 29, 2020 at 3:52 pm #20351Tom
KeymasterHi there,
What are you doing with
is_home()
, exactly?September 30, 2020 at 2:04 am #20398Alexander
ParticipantHi 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
September 30, 2020 at 4:20 pm #20444Tom
KeymasterGlad you got it sorted 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.