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
- Random sort within an already sorted query
- WP_Query offset argument does not work
- Search by Hyphen
- Exclude drafts in all() view of edit.php
- Exclude posts that only have the ‘Uncategorized’ category [duplicate]
- Keep getting same permalink with WP_Query?
- How to query posts with current or future date only
- WordPress Number of Posts Not Changing With posts_per_page
- Pagination not working on Custom Page Template
- Create new WordPress post [wp_insert_post] based on results of a WP_Query
- Exclude posts with specific meta_value while sorting by a separate meta_value
- How to add padding between posts
- Working Bootstrap Carousel Conversion to WP – Technical Questions
- Add few specific post ids to wp_query
- Custom Order in WP Query
- Search query – exact post title match
- WP_Query posts_per_page ignored
- How to get most recent commented post above new submitted post in WordPress?
- wp_query ‘s’ parameter does not work with custom post type
- How to start with post number x?
- Automatic post deletion
- 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
- how to get posts ids inside pre_get_posts filter?
- I want to get title name of post, but i didn’t get by this code. Any suggestion?
- How can I show many posts an author has per week?
- 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
- How to exclude latest x posts from a paginated query?
- 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
- Ajaxify This Code
- Pausing and Resuming WP_Query results
- How to : pagination in 3 different custom loops on the same page
- Exclude the first ‘n’ number of posts of a tag from home page?
- wp_posts table: safely remove unused columns to save database storage
- Query Posts by Custom Field
- how can i change WP main archives loop to sort by name or title
- Using wp_list_pages() after calling query_posts()
- Why are my paginated posts always returning the same results?
- Inner join overrides Advanced Custom Fields plugin’s get_field [closed]
- Loop doesn’t exclude the specified category in home page
- why the same code got different results when using query_posts in functions.php and index.php
- Query posts by Author and/or by Tag
- Migrate posts from category and sub-category via SQL
- How do I insert a after every 5 posts in a WordPress Loop that infinitely loads posts?
- WP_Query: Show 10 posts in date order, first three random
- Exclude some posts from displaying in wp_query based on some condition
- WordPress Loop: How to display recent posts in multiple divs
- Random posts that always include a particular post?
- Conflict array_splice on loop and query in widget
- WP_Query of Category Not Showing First Post
- Change content off every sixth element
- WP_Query get posts in custom database table [duplicate]
- WP query taxonomy optimization
- WordPress Query – Display 5 posts (same post type), each from a given tag
- While loop in functions.php outputting the_title() of each post on frontpage
- Show posts from two specific category in WP_Query
- How to create loop of posts except post ID defined via ACF field
- Displaying all posts from other sites on the network on one site
- Multisite how to display merged posts from two sites and sort by latest date?
- Numbered Pagination Showing The Same Posts After Altering WP_Query
- a WordPress connected to 2 database
- Using a meta_value or postdate to to query and orderby
- Exclude posts in home slider from sections
- WP_Query that targets all categories
- Fill the exclude array() in get_posts()
- Double loop output
- Ajaxify Post Sort
- Manipulate query to show specific post
- Get current user, change users post status to published
- Displaying a specific sub-category’s posts from wp_query
- My custom query is displaying random posts in random order
- Custom layout manager for posts
- Display WordPress Post By Date
- GUID to related post not in current language
- Get results from the main wp_query
- How can I display a specific number of post in a category via a url
- Advanced Post Display/Pagination/Ordering
- Pagination for custom query won’t let me back on page 1
- Make assigning post to a specific category equivalent to assigning it to all categories
- WP_Query retrieve custom posts but not the post showing
- WP_Query based on a custom field result
- How to get single post by one author?
- List posts related to category on a div [closed]
- WP_query sort by custom meta_key “price”
- Wp_query WooCommerce products
- posts_per_page – Repeats only first posts ‘post__in’ array
- query_posts different amount of posts per page [duplicate]
- How add class the_content();?
- Add custom PHP (no-SQL) filter to WP_query
- Image inside the content is replaced with featured image from my older post