Using selectattr/rejectattr with blog_popular_posts's objects

I’m trying to create a recomended carousel where I’m fetching all blog posts from a particular tag using the blog_popular_posts function. Here’s my code right now.

{% set posts = blog_popular_posts(group.id, 11, 'Animation') %}

So while this is all working, it also does include the ‘current’ page blog post and I’m trying to exclude it using the rejectattr or selectattr filter. Here’s how my code look like now.

{% set posts = blog_popular_posts(group.id, 11, 'Animation') %}
{% set posts = posts|rejectattr('absolute_url', 'equalto', content.absolute_url %}

I’m expecting it to return all the posts except the post that belongs to the current page I’m on but it’s not returning me anything.

---

For reference, here is what blog_popular_posts returns

(SizeLimitingPyList: [BlogPost 53605467259 Horror Creatures with Molly Brown, BlogPost 53675010744 Test webinar, BlogPost 53608133921 Part 1: Creating Assets and Understanding What Sells, BlogPost 53605467691 Part 2: How to Package, Price, and Sustain Your Business])

which i’m assuming are objects that should work with the selectattr and rejectattr filters?

It will work if you loop over posts to filter out the current blog’s url with an if statement e.g.

{% set posts = blog_popular_post(group.id, 11, 'Animation') %}
{% for post in posts %}
 {% if post.absolute_url != content.absolute_url %}
 <div class="popular-posts"><a href="{{ post.absolute_url }}">{{ post.name }}</a></div>
 {% endif %}
{% endfor %}

Yeah that works but I just wanted to use selectattr and rejectattr so i can filter out objects that have matching absolute_url with the page I’m on so that i can conditionally render other html with it as well.

For some reason it doesn’t work with absolute_url but it works i

{% set posts = blog_popular_posts(group.id, 11) %}
{% set posts = posts|rejectattr('slug', 'equalto', content.slug) %}

:sleepy_face:

f i use other properties like name or slug. I’ve got it to work with