Sticky Post - Recent posts

Hi There! I was wondering if there is a way for the sticky posts to stay sticky on a recent posts element.

For example, I have a Top Story category that feeds into two recent post elements. One is for the main Top story (that is sticky) and then the next feed is three of the next most recent Top Story Categories. We obviously don’t want the first top story to duplicate into the second feed so we need the sticky posts to not show there (which is a native feature with the RP element) but the issue is that the Sticky feature doesn’t make the post sticky on the recent post. Does that make sense? Is there a solution for this? Thank you!

Hi @suzannereid,

Thank you for writing in, if I understand correctly, you want the second recent posts element to ignore the Sticky Posts? If so, yes I can replicate this issue, this seems to be a bug on the Recent Posts element. I’ve submitted this to our issue tracker so the developers will be made aware of it.

For now, please have a separate category for your sticky posts so you could easily filter it in the Recent Posts element.

Cheers!

Yes that’s a problem. But I also want another my recent element to only display the stickly posts as sticky. So even if there are new posts in the category, the sticky one doesn’t move down.

Hey @suzannereid,

I think Friech meant that you create a category for posts that should be sticky like “My Sticky Posts Category”. That category won’t use actual sticky posts but just a way to display posts.

Alternatively, you might want to use Essential Grid instead and control sticky posts per grid by following the solution in this thread: https://theme.co/apex/forum/t/sticky-posts-in-essential-grid/58387

Hope that helps.

Hi @suzannereid,

I’ve been looking into the bug reported, but wanted to provide some context since I don’t believe this to be a bug. The “Ignore Sticky Posts” option simply passes the ignore_sticky_posts option into the WordPress query for retrieving those posts. This will prevent sticky posts from showing first, but they will still appear in their natural order.

What you’re looking for might be possible if run as a single query, but because you’re using multiple Recent Posts elements that means you are doing multiple queries. The next major release with the Layout Builder will offer some more advanced options in terms of how posts can be displayed.

This is possible with some custom development. I can’t give a full solution, but I can give you some ideas on how to create it.

  • Copy the code from cornerstone/includes/shortcodes/recent-posts.php into functions.php of a child theme.
  • rename the function from that code from x_shortcode_recent_posts to something else. (e.g. x_shortcode_recent_posts_sticky)
  • rename the shortcode from x_recent_posts to something else. (e.g. x_recent_posts_sticky)
  • Adjust the parameters of the get_posts call to include only sticky posts. For example:
$posts = get_posts( array(
  'orderby'   => 'date',
  'post_type' => 'post',
  'post__in'  => get_option('sticky_posts')
) );

Hopefully this helps you get an idea of what might be possible!

Gotcha–I’ll try your suggestions to work out a solution. Thank you!!

Also, is there a way then to exclude sticky posts from the main recent posts element?

Hi @suzannereid,

The question is a part of customization which is outside of our support scope. We will not be able to perform the customization, but we will do our best to get you started with the case.

You will need to follow the instructions that @alexander suggested, but this time you need to use post__not_in instead of post__in. That will make sure that the posts that are not sticky will show.

Thank you.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.