Navigation überspringen

[Gelöst] Filter on Number of Comments

This support ticket is created vor 3 Jahren, 4 Monaten. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Dieses Thema enthält 2 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von aaronM-9 vor 3 Jahren, 4 Monaten.

Author
Artikel
#2189181

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

#2189505

Nigel
Supporter

Sprachen: Englisch (English ) Spanisch (Español )

Zeitzone: 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);
#2189801

Excellent. Thank you!