September 27, 2020 at 9:32 am #20125
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 BeckwithParticipant
Its working on my test site – do you have a link where we can see the issue?September 28, 2020 at 11:31 am #20239
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 #20241
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?September 28, 2020 at 12:11 pm #20244
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.September 29, 2020 at 3:52 pm #20351TomKeymaster
What are you doing with
is_home(), exactly?September 30, 2020 at 2:04 am #20398
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()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_postsfilter to include sticky posts (that do match the category/tag/etc).
I’ll mark the topic as resolvedSeptember 30, 2020 at 4:20 pm #20444TomKeymaster
Glad you got it sorted 🙂
- You must be logged in to reply to this topic.