question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to obtain comment count for a list of posts?

See original GitHub issue

fetching the comment count for a single post is a breeze using const { count } = useComments()

However, how would you go about fetching the comment count when you have a list of multiple posts?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
vbylencommented, May 30, 2021

Works like a charm!

I’m excited to see what else you come up with 😎

1reaction
lawrencecchencommented, May 29, 2021

Entire view query for context:

create or replace view comments_thread_with_user_vote as
    select distinct on (id)
        p.id,
        p.slug,
        p."createdAt",
        p."updatedAt",
        p.title,
        p.content,
        p."isPublished",
        p."authorId",
        p."parentId",
        p.live,
        p."siteId",
        p."isPinned",
        p."isDeleted",
        p."isApproved",
        p."html",
        p."isSpam",
        p."author",
        p."votes",
        p."upvotes",
        p."downvotes",
        p."depth",
        p."path",
        p."pathVotesRecent",
        p."pathLeastRecent",
        p."pathMostRecent",
        coalesce(
            (
                select
                    v."value"
                from
                    votes v
                where
                    auth.uid() = v."userId" and v."postId" = p.id
            ),
            0
        ) as "userVoteValue",
        coalesce(
            (
                select
                    count (distinct id) - 1 -- Remove self
                from
                    comments_thread c
                where
                    p.path <@ c.path
            ),
            0
        ) as "childrenCount"
    from
        comments_thread p
Read more comments on GitHub >

github_iconTop Results From Across the Web

Show comment counts in your post lists
To show a post's comment count in an index or list view, simply add the following HTML where you want to show the...
Read more >
get_comments_number() | Function
Retrieves the amount of comments a post has.
Read more >
Howto show comment count by post in post?
I would like to show comment count IN the post (not in post meta), is there a snippet how to do this or...
Read more >
List Popular Posts By Comment Count - WP SITES
List Popular Posts By Comment Count. In this post, i'll show you how to create your own new WP_Query & custom loop. Your...
Read more >
Get number of approved comments of post - Stack Overflow
The problem is: It returns the total comment count (including deleted comments etc.) I only want to show the number of approved comments....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found