I would like to create a View that only shows posts with a minimum number of comments. Can you tell me how I might go about doing this with Toolset? Thanks.
- Aaron
Nigel
Supporter
Languages:
English (English )
Spanish (Español )
Timezone:
Europe/London (GMT+00:00)
The number of posts is stored as a standard field in wp_posts.
Views doesn't offer filters for standard posts in the UI, but you can use the wpv_filter_query API hook to add the argument yourself.
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
Here's an example to limit a View results to posts with at least one comment:
function tssupp_filter_query($view_args, $view_settings, $view_id)
{
if (in_array($view_id, array( 123 ))) { // Edit View ID
$view_args['comment_count'] = array(
'value' => '1',
'compare' => '>='
);
}
return $view_args;
}
add_filter('wpv_filter_query', 'tssupp_filter_query', 101, 3);