get_comments
accepts an array of arguments, you are passing an integer.
If you want to retrieve all comments for a post use:
get_comments( array('post_id' => $post->ID, 'status' => 'approve') );
To get an already formatted comment list, is easier use the wp_list_comments()
function, instead of another foreach cycle (code from codex):
echo '<ol class="commentlist">';
//Gather comments for a specific page/post
$comments = get_comments(array(
'post_id' => $post->ID,
'status' => 'approve'
));
wp_list_comments(array(
'per_page' => 10, // Allow comment pagination
'reverse_top_level' => false //Show the latest comments at the top of the list
), $comments);
echo '</ol>';
Related Posts:
- Can’t show comments count per post outside loop
- Display posts with comments closed, with pagination?
- get_next_post() and get_previous_post() return wrong posts
- Inserting custom data to the_post() during loop
- How do I restart my loop with get_next_post()?
- Post Loop Missing Most Recent Post
- Pagination with an array of post objects?
- How to get posts and comments amount per hour, per year and per month?
- Shortcode for Comments and Comment Boxes in Post Loop
- How to get all posts in gallery post format template
- External link not showing on post but showing on comment
- Displaying posts on Homepage
- posts_per_page – Repeats only first posts ‘post__in’ array
- View post with specific category id and name which I selected in the backend (drop-down option)
- Page and post loop same template
- WordPress Query Posts From Category Post on Static Page
- How to create a “latest news” page showing a list of posts from blog category
- ACF to select posts not displaying on blog page
- Add custom text automatically on each post
- Getting blog pagination to work on page set as front page
- Extracting relevant tags associated with that particular single post only
- Make loop inside slider divisible [closed]
- How to add automatically bootstrap 4 order-lg-1 and order-lg-2 classes for columns in foreach loop based on the count?
- Why this function doesn’t works without the_post?
- Post Filtering by GET URL parameters
- How to style archive post titles… but only those posts who have comments?
- Display current post position in Elementor Posts widget
- How to give classname to post if post has no content?
- Loop through posts? Want to remove extra newlines in actual post HTML/content on backend
- WP_Query: Show 10 posts in date order, first three random
- Custom Articles page only showing a limited number of posts per page
- How include css class based on post ( in loop ) slug?
- WordPress Loop: How to display recent posts in multiple divs
- Querying another post category to match current post and display in loop
- Related Posts function not working
- How to display posts on custom page without declaring a posts page in reading settings?
- Show posts by quarter
- separate the post of a category by subcategory
- How to get post with slug and exclude categories
- How to display post list in a table layout (multiple queries in single loop)
- Is it advisable to use $post->comment_count instead of get_comments_number( $post_id )
- How does WP decide how to display a page
- Cannot implement byline into posts container in single.php
- Not all posts showing in query
- how to handle the loop using filling bootstrap grid structure?
- Optimizing the blog loop
- How to check if there are posts with the same tag
- WordPress loop not working on static front page
- get_posts not pulling the correct number of posts
- Get x recent posts by author?
- Accessing Post ID Within Loop
- Some doubts about how the loop work (trying debugging it)
- Display on page every post in blog WITH comments
- Custom WP_Query not working correctly
- Different number of posts per row in grid layout
- Optimize CPT-function with a loop
- Showing recent post of category in page
- Display specific posts on home page
- The loop starting at a certain ID
- linking to post outside the loop
- WP_Query of Category Not Showing First Post
- If custom field is empty, use one from a previous post
- Cant’ Grab WordPress Built-in Posts Through Loop
- Can WordPress handle following functionalities?
- How come this loop is not working? [closed]
- Loop not showing first post
- If post does not exist, do something
- List latest posts with least comments in WP-Admin
- Internal linking to posts permalink fail because of spaces and stripe at postname
- If post exists, make it a comment in existing post with same name?
- Get post category as a separate string and url
- Limiting the amount of posts retrieved by the loop
- Display 3 posts with different HTML markup using a loop
- Pagination for normal (standard) posts on a page with a custom loop?
- Changing wp_link_pages() to “Next Page” and “Previous Page” buttons?
- I can’t find the relevant part of the loop in my theme file. How do I find the full content with “More…”
- Get posts from current category?
- posts going to 2 pages/categories only show up in 1
- How to repeat a loop after 4 posts [duplicate]
- Custom Post Type Single Loop Outputting Wrong Post
- Using the loop to set locations for all posts on a single google map
- How to separate each individual blog post?
- How to get post id of last approved comment?
- Defining ‘last’ class on foreach blog posts
- Get current taxonomy and display query accordingly
- How to show full post on home page
- How to implement a WordPress comments function?
- Error while excluding a post from another loop (using its ID)
- Is there a way to define the $post var outside the loop?
- How to add content above footer in posts from specific category
- Allow / show post comments in category pages
- How to show multiple posts thumbnail, title and date in widget
- I need to create “View Profile” and “Edit Profile” links by incorporating the Post Title/ID, but can’t seem to manage it
- ACF flexible content block not showing on live site (works locally)
- Only the most recent post is showing on my category page (working on localhost, not live site)
- Show only posts with titles/permalinks that do not contain certain words
- Want to change the post every three days with in specific category
- Count the total views of all user posts published
- Separate top level categories on archive-product.php by meta
- While loop in functions.php outputting the_title() of each post on frontpage