To quote the Codex on the have_comments function:
This function relies upon the global $wp_query object to be set – this is usually the case from within The Loop
The problem is that your ajax handler creates its own WP_Query object. Note that you are not calling the_post(), instead you are calling $posti->the_post(). Same logic applies to comments as well.
Try the following:
if ($posti->have_comments()) {
echo "Comments ok";
} else {
echo "No comments";
}
Related Posts:
- Allow variable amount of comments before pagination
- Ajax Load More Posts in Category Page
- How to load paginated post pages via ajax
- Getting the post_id in wp_ajax function
- get comments and get posts in loop
- Load posts dynamically
- How to load post content on index page using ajax when post title in sidebar is clicked
- This AJAX Code Doesn’t Work – Looking for elegant solution
- One comment per user email per post
- Cannot access current post’s ID in custom plugin
- Can’t show comments count per post outside loop
- Only display posts with comments
- How to output comments number of a post per day?
- Load post content into div with ajax
- “Uncaught SyntaxError: Unexpected token
- Hide comments awaiting moderation from user who submitted the comments
- WordPress theme ajax have_posts()
- Including new Javascript only after a comment is made
- How do I use Ajax to show the new posts realtime, on the frontpage
- how load content as pop-up using ajax
- Display posts with comments closed, with pagination?
- Load content in a div with ajax
- When trashing a post, also trash related comments
- How to create a load more post entries like Twitter?
- slideshow is not showing in a post call with ajax
- Posts vs. Pages
- how to set beforsend option in wordpress ajax methods
- count the total number of comments the user has received for his published posts
- Filter Custom Post Type by Category with Ajax
- Ajax posts filter by date, comments, top views, top likes
- JSON – Permission Error?
- Ajax Dynamic Archives not showing correct results
- WP_Query with ajax handler returns the same posts
- How to allow logged in users to post anonymously
- Email entire post contents
- Query get post,how to add comment box
- Two loops, one AJAX loop, exclude posts in first loop from second loop, loops are in different files
- Update all comments time to random dates?
- Ajax post filters not working
- Enable Comments Box On Custom Post Type
- Turn On Comments On Custom Post Types in Directory Theme
- Move comments only from one WP installation to another
- Second comments section for one post/page
- Using ajax on editing a category edit page?
- Showing author page if user has no post
- Customizing Comments on Posts
- Auto-realod with new posts // Ajax call
- What do comments with […] mean?
- Internal post link creates comments on its own
- Dynamically switch template on click
- How to get posts and comments amount per hour, per year and per month?
- Show comment number per author per day
- Get all comments of author’s posts
- SQL Command for restoring trashed comments
- How do you change the comment count in the back end posts list, to reflect unapproved comments, rather than all comments?
- Hide comments and posts posted by other user
- Let both the admin and post author update comment meta
- How to style archive post titles… but only those posts who have comments?
- wp_query with ajax
- Call current post URL in ajax
- After ajax image is outside the “ tag
- Is it advisable to use $post->comment_count instead of get_comments_number( $post_id )
- Retrieve post in AJAX Callback
- How does WP decide how to display a page
- Showing recent post of category in page
- Can WordPress handle following functionalities?
- How to get post id of last approved comment?
- How to implement a WordPress comments function?
- how to show comments only author which send own posts in wordpress
- Shortcode for Comments and Comment Boxes in Post Loop
- Merge get_comments & get_posts into a single query
- Using AJAX to filter posts without refreshing page
- Unable to delete attached file from folder programmatically
- Javascript – How do I get specific post fields?
- Remove the URL author of post on all comments
- Ajax: load content from post I clicked
- call to jquery ajax failing with 500 error when passing extra data field
- Comments are in database, don’t show up in WordPress backend or frontend
- No comments allowed
- Many buttons not functioning in WordPress dashboard (as admin)
- I want to change the WordPress comments file
- AJAX load more posts not using correct category and repeating the same few posts
- Ajaxify Post Sort
- WP_Query extended with AJAX
- Some comment box wordpress in 1 post [closed]
- 3rd Party Login in wordpress
- How to get posts from network blog
- How can I get a comment ID on Submit?
- Get first comment link on the post itself
- Display the first post’s comments of category in comments.php template
- 2 tick boxes appearing below comments
- Adding a time stamp on post view
- How to display a certain template element only for posts published within certain time range?
- Ajax calls in wordpress
- How can I show the positive and negative comments for a same post separately?
- How does WordPress add the comments and comment form to posts
- How to make ‘show_option_all’, that comes from wp_list_categoreis, to work with get_categories or with get_terms?
- How to update wp_posts with just the returned comment count from wp_comments (SQL GROUP BY)
- Undefined Function Fatal Error with Shortcode [closed]
- Best method for comment section associated with different images?