$comments
, or $wp_query->comments
, is initialized by comments_template()
, which you call in your template file when you want to load the comment sub-template file. So at the time of template_redirect
it is not yet initialized. As Chris said, you should call get_comments()
and pass it the post_id
of your current post.
If you’re doing AJAX calls, even not from the admin side, you can use wp-admin/admin-ajax.php
and use special actions hooks. This shortcuts the usual post queries, which you don’t need anyway.
Related Posts:
- Comment filtering (search)
- Prevent WordPress from loading comments
- Fastest way to get the comment and ping total count for a post
- How to remove comment section from page only , not from posts pages?
- How to load and show comments with AJAX instead of pagination?
- Need help with friendly URL’s in WordPress
- Modify column_author in WP_Comments_List_Table
- When adding a custom REST endpoint, where do you put the endpoint function, and where do you put the function registration call?
- difference between esc_attr(), strip_slashes(), strip_tags()?
- Adding Custom Fields to WordPress Comment Forms?
- Get the sidebar ID in which the current widget was dropped
- Change comments form title on a page by page basis
- media_handle_upload weird thing
- Change “logged in” link in (you must be logged in to post a comment)
- Limit comments displayed on basis of user_id
- How to add default images into theme customizer image control?
- How wp_ajax_nopriv since WordPress 3.1
- WP_Query with the “offset” argument
- WordPress Ajax Data problem
- How can I & how do I change text displayed in comment via child theme
- multiple comment text areas
- How to use get_option() without any filter?
- Add filename to attachment page url
- Count widgets of a certain type
- Widget Javascript code (ajax)
- How to display something in a div when the user clicks on a text in another div – no page refresh [closed]
- Comments not nesed with custom template
- Custom Login and Registration form in Ajax
- Comments Confusion
- Calling a php file from a javascript file in wordpress
- show the meta values to visitors that collected via coment form
- Add Div to Comment Form
- Trying to implement Ajax comments in WordPress, getting WP error
- Load more posts with multiple queries
- Author Tracking Code!
- want to create a subcategory.php to manage subcats
- Customize Theme comment template to Insert VoteUp and VoteDown buttons
- Viewing checkout page removes fees from mini cart
- Load MediaPlayerElement after Infinity Scroll loads more posts
- changing font size and font of a custom message added after comment
- How can I display a PHP foreach loop’s answers by AJAX
- How to add a do_action on refreshing of WP customizer?
- Highlight comments of all the site authors
- Custom comments list, right depth
- Adding comments to my custom theme
- WordPress : using AJAX to get posts & Sidebar Content to an external application
- Ajax search shows all results when user empties input?
- Is there a hack for using is_page() within the function.php file?
- Customizing Comments
- Attach File Funcion for Common people
- Custom Database Table and foreach
- mailchimp integration on a custom footer
- How can I style the Comment Section of a blog post
- POST 429 Error when trying to place more than 20 images into post at once
- Automatically reject a comment if website field contains anything
- Custom Avatars for WordPress Comments VIA Website URL?
- How to submit form data in the same page in WordPress without reloading the page?
- Real time notification on user profile after new comment
- Show comments based on user role in front end
- Edit a custom admin page
- Unable to show messages using ‘admin_notices’
- Customized Comment Form Issues
- Changes in comments.php in the child theme does not show up on the site
- How to fix vanilla comments extra iframe space
- Post thats in Two Categories, only want to display name for one
- Custom Slider Per Page created
- Creating php pages in wordpress and assigning them to wordpress pages
- How do I create a root link in wordpress to a PDF file?
- theme customizer – can a single option pass multiple values?
- get_delete_post_link( $post->ID ) is blank when logged in as “subscriber”
- How to Escape Custom Meta Data And Prefix Custom Meta ID
- Separate header for static home page and posts page
- Upload a web module (html and JS) to wordpress
- How to remove Customizer’s Section and move Control straight to Panel using Child Theme
- Proper way to use WordPress function with AJAX PHP file
- Remove Customizer Control Choices (Type: Radio Array) using Child Themes
- Grabbing a data from wp_usermeta
- Position a hard-coded menu item
- How can I include the user id inside of a shortcode php output?
- Restrict content access to logged in users
- How can i create menu like in the example?
- wordpress shortcode not working
- Errors being created by admin-ajax.php
- Comment “like” problem – “users who like this” avatar linking to current user profile instead of “liker’s” profile
- Remove welcome panel from contact form 7 page [closed]
- post_content is stripping HTML when adding a new post? [closed]
- WordPress Code Snippet to count total posts by author
- Loading Posts & Category with Ajax
- How to use AJAX in WordPress in MYSQL query?
- After disabling WPML multi currency, the currency is still handled by the WPML
- How to remove admin menu pages inserted by plugins and themes in the top admin bar?
- WordPress custom dropdown listings
- Can ‘edit_form_after_editor’ messages be varied for specific pages?
- Customizer – How to get theme mod range value?
- How do i wrap woocomerce attribute in list?
- Custom login and registration forms
- Remove header title form page through CSS [closed]
- get_theme_mod outputs number when using WP_Customize_Cropped_Image_Control
- Save Textarea on WordPress Frontend
- How to display page ids as page slug names?