I like the idea proposed in this comment. Connecting the posts table to the comments table seems like it’d be some super complicated SQL (well all SQL is complicated to me). Instead the link proposes that you add a post meta field to the post to hold the date of the most recent comment.
add_action('comment_unapproved_to_approved', 'wpa_144482_comment_approved');
function wpa_144482_comment_approved($comment) {
$comment_post_ID = $comment->comment_post_ID;
$date = $comment->comment_date;
update_post_meta( $comment_post_ID, '_recent_comment_date', $date );
}
Then you should be able to sort your posts by the _recent_comment_date field.
There is also the Filter by Comments plugin but it hasn’t been updated in a long while so I couldn’t vouch for it.
Related Posts:
- How to limit the number of posts that WP_Query gets?
- Should we trust the post globals?
- Get current post id in functions.php
- WP_Query offset argument does not work
- Querying post from a multisite network
- How to know if get_posts() failed?
- Show related posts by category but ignore one category
- post__in for get_posts with a dynamic array
- Keep getting same permalink with WP_Query?
- How to query posts with current or future date only
- Pagination not working on Custom Page Template
- Create new WordPress post [wp_insert_post] based on results of a WP_Query
- Post content being duplicated by the_content();
- How to add padding between posts
- prevent showing posts of an specific category in admin posts section
- Working Bootstrap Carousel Conversion to WP – Technical Questions
- Search widget breaks when using multiple loops?
- How to change bulk post status
- Add few specific post ids to wp_query
- WP_Query posts_per_page ignored
- wp_query ‘s’ parameter does not work with custom post type
- WP Query related posts by current page Tag ID
- WP_Query get posts from custom posts by category
- Accessing post->ID outside of the loop for listing child pages
- WP Query – duplicated posts once including tags in search results
- List posts in a given category
- Reset Popular post query?
- Query Posts multiple conditions
- how to get posts ids inside pre_get_posts filter?
- Future post ID not showing
- How do I use WP_Query to get a range of posts with custom fields that have numbers with letters in them?
- recent posts for different categories
- Search by post title and content in wp_query without order
- Change post order random through out the entire WordPress
- Setup a custom dynamic post
- Anyway to grab author name and featured image in an embeded in inital array of posts outside of loop?
- Removing noindex posts from wp_query
- How safe is renovating $wp_query when doing WP_Query pagination in Page Template
- Exclude the first ‘n’ number of posts of a tag from home page?
- wp_query random post
- wp_posts table: safely remove unused columns to save database storage
- Using wp_list_pages() after calling query_posts()
- how to get post order by post id wp_query?
- Possible to alternate between two loops
- How to display all posts divided/ordered by post date? [closed]
- Why are my paginated posts always returning the same results?
- Is it possible to use WP_Query to only pull posts with attachments?
- Inner join overrides Advanced Custom Fields plugin’s get_field [closed]
- Every second post different class in blog view
- Display posts of specific category term
- Query posts by Author and/or by Tag
- Can’t understand why sometimes a [caption] field appears
- Why in my query is display two title?
- Migrate posts from category and sub-category via SQL
- wp_query with ajax
- How to give classname to post if post has no content?
- Exclude some posts from displaying in wp_query based on some condition
- How to convert query sql to shortcode in wordpress?
- Use posts_where to exclude posts ids from wp_query
- Why does WordPress search returns same number of results for every search query?
- Sidebar limiting to 10 posts?
- WP_Query get posts in custom database table [duplicate]
- WP query taxonomy optimization
- Override WordPress core post-template.php block template
- Change Old WordPress Post Date Year
- Displaying all posts from other sites on the network on one site
- Display/Filter post using if else statement
- Search results for ACF data
- Multisite how to display merged posts from two sites and sort by latest date?
- Query prints posts without specific categories
- Numbered Pagination Showing The Same Posts After Altering WP_Query
- Using a meta_value or postdate to to query and orderby
- Exclude posts in home slider from sections
- Ajaxify Post Sort
- Loop through all posts showing duplicates
- Manipulate query to show specific post
- Get current user, change users post status to published
- WordPress text field in array problem
- Random order of the 5 most popular posts
- My custom query is displaying random posts in random order
- Get query result according to merged array
- Display WordPress Post By Date
- GUID to related post not in current language
- How can I display a specific number of post in a category via a url
- Advanced Post Display/Pagination/Ordering
- How to show the posts list into a static page? Problems to use the loop into a static page
- Order posts by separate menu order for different sub-categories
- Displaying Results From Custom Taxonomy Query
- Make assigning post to a specific category equivalent to assigning it to all categories
- Multiple loops on a Search result page?
- WP_Query retrieve custom posts but not the post showing
- WP_Query: Fetch posts that are in (category1 and not in category2), OR posts that are not in cagegory1
- WP_Query based on a custom field result
- How do I show the post title if an advanced custom field hasn’t been used?
- WP_query sort by custom meta_key “price”
- How add class the_content();?
- Add custom PHP (no-SQL) filter to WP_query
- Get related posts matching most of the provided tags using WP_Query
- WP_Query post_tilte search in posts table
- Is it possible to use the_post 2 times in one loop