Sticky post not showing in Loop
-
Superb plugin. But in my Loop I can’t manage to show a sticky post, even setting parameter ignore_sticky_posts as FALSE
-
Hi @birous, I’m glad to hear that you’re enjoying the plugin overall! I just tested this on my end and I’m getting the opposite behavior: whether I set
ignore_sticky_posts
to true or false, it always seems to be displaying my sticky post. This sounds like a bug, so I’ll report it to the dev team and have someone follow up here when it’s resolved.Hi again @birous, I just heard back from the dev team and it seems that not only was the
ignore_sticky_posts
attribute initially designed in a fairly limited way (it apparently only works when is_home() is true, which would be pretty rare), but they also noted that having this be a boolean attribute (true/false) is unnecessarily limiting.To fix the issue and improve the usefulness of that feature, the team is going to deprecate the
ignore_sticky_posts
attribute and add a new attribute,sticky
. This attribute could be set to one of four values:default
would show all posts as normal,first
would show sticky posts before the other items in the loop,only
would loop through only the sticky posts, andhidden
would hide sticky posts, only looping through non-sticky posts. It sounds like when this is released,sticky=only
orsticky=default
would achieve what you’re trying to do.I’ll confirm when this makes its way into the released version, but I figured I’d follow up here so that you can keep an eye on the changelog for this feature being added.
@bentangible Thank you for replying. Eager to see this new release feature.
sticky=first
is what I’m looking for!- This reply was modified 1 year, 7 months ago by birous.
Hi @birous, I’m happy to report that the latest version of the plugin includes the new
sticky
query parameter that allows you to work with sticky posts in theLoop
tag more easily than before. It works a little differently than how I’d suggested earlier, so in the end, it accepts three possible values:sticky=true
puts sticky posts at the beginning of the loop (sounds like this is what you’re after)sticky=false
excludes sticky posts from the loop altogethersticky=only
loops through only sticky posts and ignores non-sticky posts
If the
sticky
query parameter isn’t set, the loop simply ignores whether a post is sticky or not and loops through all posts as usual.Let me know if you have any other questions or issues!
Sorry to inform that
sticky=true
didn’t work for me at all. On the other hand,sticky=only
worked well as intended.Hmm, I just tested this and it seems that if you create a loop and add query parameters that aren’t related to sorting, the sticky parameter seems to work as expected:
<Loop type=post sticky=true>
But if you add any query parameters that sort/order the loop, that sorting takes precedence and the sticky posts end up tossed back into the middle of the posts.
<Loop type=post orderby=date sticky=true>
Do you have query parameters on your loop that are sorting the loop in some way?
In general, the developers design things to mimic core WordPress functionality as closely as possible to keep things as efficient as possible, so this might be one of those cases but I’ll confirm whether this is the intended/necessary behavior for this feature. In the short term, if you need to sort your loop based on something and also show sticky posts at the top, it should theoretically be possible to stack two loops, the first where you set
sticky=only
and the second where you setsticky=false
. A bit more verbose, but I assume that should achieve what you’re looking for while also still being able to sort your loop based on some other factors. It might even be possible to compact these two loops to avoid needing to repeat your inner content multiple times with something like:<Set query=post_loop_1 type=post orderby=date sticky=only> <Set query=post_loop_2 type=post orderby=date sticky=false> <Loop times=2> <Loop query="post_loop_{Get loop=count}"> Your inner loop content... </Loop> </Loop>
Obviously a little bit more markup than might be ideal, but then you also have a lot more control over how each query works.
I’ll let you know what I hear back from the devs about whether this behavior of ignoring the sticky parameter on sorted loops was intentional or necessary.
@birous I heard back from the dev, it seems that this behavior wasn’t intended/anticipated and a fix has been implemented. It will make its way into the plugin version on the WordPress repo eventually but if you want to grab the latest version of the plugin that includes the fix to your issue before it comes out through a version update, you can use this link to download the zip file. I’ve just tested it on my end and it seems to be working as expected. Let me know if that fixes your issue!
Also, I thought you might be interested in knowing that the issue you initially noted with the oldignore_sticky_posts
parameter wasn’t actually an oversight in the development of L&L, it’s actually an issue with the WordPress core. Even Gutenberg itself doesn’t make sticky posts sticky anywhere other than when is_home() is true. So I guess with this new sticky feature, L&L works more sensibly than WordPress itself. Crazy! Anyway, I just thought I’d share since I thought that was interesting.
- The topic ‘Sticky post not showing in Loop’ is closed to new replies.