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
- How to display comments and comment form on custom post type?
- Can I load posts via Ajax?
- Load posts dynamically
- Comments are assigned to wrong or related post
- How to load post content on index page using ajax when post title in sidebar is clicked
- How can I allow editors to leave comments on posts that have not yet been published?
- Update post date on every new comment?
- How to use oEmbeds on Post Content during AJAX requests
- Show Custom Taxonomy Categories, Listing of Posts, and Single Post via AJAX
- 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
- 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
- Display on page every post in blog WITH comments
- Using AJAX and PHP to load next post object
- Showing recent post of category in page
- Can WordPress handle following functionalities?
- If post exists, make it a comment in existing post with same name?
- How to get post id of last approved comment?
- Automate post update for all posts?
- How to implement a WordPress comments function?
- Allow / show post comments in category pages
- How to make ajax load posts from the current category?
- Count the total views of all user posts published
- 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
- Passing values via an Ajax querystring
- Unable to delete attached file from folder programmatically
- Javascript – How do I get specific post fields?
- How to create custom search form function including post “tags”
- how to filter posts by category without page load (ajax) in wordpress?
- Remove the URL author of post on all comments
- Ajax: load content from post I clicked
- WP Ajax returning 0, can’t find action
- call to jquery ajax failing with 500 error when passing extra data field
- WordPress weird behaviour on comments
- 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)
- Post data across WordPress sites
- I want to change the WordPress comments file
- Ajax post doesnt call succes after got the response
- AJAX load more posts not using correct category and repeating the same few posts
- Order result from ajax
- Ajaxify Post Sort
- Colorbox not working on native WordPress gallery when gallery is loaded thru AJAX
- Dynamically load posts based on category
- WP_Query extended with AJAX
- Ajax the create and edit post form into lightbox and get results
- Posting a comment redirects admin/users to blank page
- Ajax – Post Categories and Load More
- How to enable comments meta box for other author posts?
- Comments as part of a post
- Some comment box wordpress in 1 post [closed]
- WP Load post with ajax and apply isotope
- No comments on static front page
- 3rd Party Login in wordpress
- How to get posts from network blog
- Trash a post, send associated comments into the trash bin (change status)
- Apply comment to different post (not the current post) [duplicate]
- How can I get a comment ID on Submit?
- External link not showing on post but showing on comment
- Get post id on click of thumbnail
- Get first comment link on the post itself
- Get url/link to latest comments in a post
- Display only posts with comments
- wp_query select if have comments
- 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?
- Admin moderates ALL comments (including post author)
- Show List of Posts With Comments Open
- 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)
- Simple shortcode to check if a user has commented on a certain post
- Undefined Function Fatal Error with Shortcode [closed]
- WordPress Ajax load doesn’t work
- Best method for comment section associated with different images?
- Code understanding
- post comment dont show the pdf file wordpress
- Implement AJAX ‘load more’ with offset posts
- Xhr.send : PDF upload failed with status 400 and response 0
- Comment count next to post title?
- /wp-admin/admin-ajax.php Error 500 while using divi premade layout in existing pages