Did you actually find a case where there are any real comments in the wp-query object after running a normal query?
If you examine the code in class-wp-query.php, you should find that the comments field only is populated with comments when a “comments-feed” is being queried for.
In normal operation, comments are not retrieved by the WP_Query, but instead retrieved by using WP_Comment_Query, and this does not happen until your theme calls the comments_template() function.
As such, you can use the ‘comments_template_query_args’ filter to filter the arguments passed to that class before the comments are displayed on the page. This won’t affect the comments feed, because those are indeed populated by the main WP_Query, but only for the comments feed case.
Related Posts:
- prevent get_comments() from returning comments not in comment__in
- WP_Comment_Query pagination, delving into the unknown
- Get posts with condition on comment meta value
- WP_Query sort by comment meta data
- Get number of comments after modifying comment query
- using wp_query to return posts w/ comment count > 0
- How to target the default Recent Posts and Recent Comments widgets with pre_get_posts?
- Query posts with more than 20 comments
- How can I retrieve comments from last 5 minutes for a post?
- Sorting posts DESC based on the number of comments using WP_Query
- Most commented last 24h, week, month, year and all time – posts_where
- Most commented post showing 2 records
- WordPress Comments sort by custom meta key
- Query posts by last comments
- How to list posts with disabled/closed comments, with pagination?
- I need help using pre_get_comments to limit comments in the comments admin screen
- All Posts Have The Same Comments
- Is it possible to give a classname to specific comments in the WordPress admin?
- How to get_comments() ordered by date and parent?
- Comments orderby comment date not working
- How to display comments list by order when clicking on newest or oldest link?
- Get comment number by date range?
- Set Alias for meta_query arguments in get_posts()
- How can I use order_by to order by two meta_keys without excluding posts that don’t have those keys initialized?
- Loop within a loop?
- Ajax and WP_Query/tax_query parameter
- Sorting Posts by custom field
- Order posts by date and then by custom field
- Hide posts from users with a specific role
- Show most popular post of last 12 months
- WP_Query to get posts in a specific category and post format
- Can’t get drafts with WP_Query using post_status parameter
- Get ONLY the count from wp_query without fetching posts
- Different string for specifed post type on posts listing at homepage
- How can I order Wp_Query hierarchically?
- Order by custom table and multiplication
- WP_Query ajax loader detect end of posts
- How to get count of posts assigned to given category?
- WP_Query posts by distance based on LAT & LNG in Database
- Changing WP_Query params with url Query Var
- From where is archive.php getting its posts?
- Wp redirect to url with ampersand string
- Change query based on post type while staying in loop
- Access WordPress query by index number outside the loop
- Custom Pagination Layout for Elementor widget
- Pagination outside of loop
- Multisite – Global CPT – advices?
- $WP_Query: How to display excerpt on first post only
- How to properly reset a nested WP_Query query
- Gallery shortcode numerical sorting
- Is there a reason why Pages are not publicly_queryable?
- Check return value of get_posts
- How Can I Change The Tax Query For The Main Loop For Taxonomy Archives?
- Get a list of posts by specific category
- WordPress Query String: get_posts(‘cat=5’) vs WP_Query( ‘cat=5’) vs URL: /site/?cat=5
- WP_Query – Adding “offset” posts to the end of the loop
- Multiple wordpress queries with nested output (odd – even)
- it’s possible make a WP_Query with math operations?
- show posts with range meta key
- how to write wordpress query for multiple metakeys checking?
- Using a Shortcode to List Posts from Multiple Categories
- How to display a list of posts in same child category as current post
- querying posts with a custom status
- Display post meta conditionally based on it’s value
- How can i show pagenavi in my author.php?
- Randomly select one of last 3 posts
- Query multiple meta key values for template
- Using WP_Query with multiple loops on one page in search.php
- Order by post meta not working with pre_get_posts filter
- ACF: How to query for a given value count of an array like field? (e.g.: How many rows has a `flexible_content` field?)
- is_user_logged_in not working from WP-API (wp-json)
- WordPress private post won’t display to other admins
- Only show tag with the same id as the post
- ACF: How can I publish values of ACF fields in a loop while using wp_query?
- Sort by price wpdb
- WP_Query random ordering not working since 5.4
- Show a message if there are no active posts in category
- Where my home page and font options has gone?
- How to get the latest post list (of the parent custom custom type)
- Problem with my loops
- 404 page on custom search pagination
- next_posts_link not visible on first page
- Paging works correctly on local version, but not live?
- Create global array to compare inside a query
- Pagination not working in custom loop WP_Query
- Hi , i am trying to set the post for 24 hours and with it will be changed
- Own query vars are not displayed
- Show full category tree for a year with all post titles?
- Trying to use “Medium” featured image for custom post type on home page
- Filter posts/pages by user_role array
- Display images with same specific value?
- WP_Query with meta_value_num and meta_query not paged correctly
- I need value of saved meta to display next to the post it is associated with
- Post Query not working after updating to 4.1
- Search Query that Includes Custom Table
- Pagination with WP_Query not working
- new WP_Query based on average values of meta fields
- Custom post types loop on a page template
- Can’t seem to get an else statement correct? [closed]
- WP Query returning all posts when Meta_query is null