I’ve looked at numerous examples of wp_query and can’t figure this out. If the thing I was comparing were a meta value then I could to a meta query, but apparently you can’t do a compare with a non-meta value?
This is what I thought it would work:
$commentpost = new WP_Query( array( 'key' => 'comment_count',
'value' => '0',
'compare' => '>',
'orderby' => 'comment_count',
'order' => 'DESC',
) );
Any help would be appreciated.
While the
WP_Query
class has the native possibility toorderby
thecomment_count
, it doesn’t have the same to query based on those. But when we look at theposts
-table, we can see that there isn’t much we need to alterSo the thing we could do, is intercept the query and modify the
WHERE
clause inside theposts_where
-filter.You still have to fill in the bits like cases where you don’t want to intercept the query. Keep in mind, that it’s not tested.