Meerkat

Meerkat

The "where" Filters

The where filters provide the greatest control when querying comments across arbitrary comment properties. For example, you can apply comparison operators, or check an arbitrary property against a list of provided values.

#The where Filter

The where filter accepts a comment property, a comparison operator, and a check value as its arguments. You may refer to the comment properties documentation to see what is available when using this filter (custom addon values are also supported). The following example demonstrates how to find all comments that have more than six revisions:

1{{ meerkat:responses filter="where(revision_count, >, 6)" }}
2 
3 {{ comments }}
4 <!-- Render your comment thread here. -->
5 {{ /comments }}
6 
7{{ /meerkat:responses }}

Remember that all filters can be chained, including the where filter. The following example expands on the previous, and returns only those comments that have more than six revisions, but less than ten:

1{{ meerkat:responses filter="where(revision_count, >, 6)|where(revision_count, <, 10)" }}
2 
3 {{ comments }}
4 <!-- Render your comment thread here. -->
5 {{ /comments }}
6 
7{{ /meerkat:responses }}

#where Comparison Operators

The following table lists all of the comparison operators that are supported by the where filter:

Operator Description
= Lose equality operator; the data types do not need to match.
!= Lose inequality operator; the data types do not need to match.
== Strict equality operator; the data types must match.
!== Strict inequality operator; the data types must match.
> Great than; the comment property must be greater than the check value.
>= Greater than or equal to; the comment property must be greater than or equal to the check value.
< Less than; the comment property must be less than the check value.
<= Less than or equal to; the comment property must be less than or equal to the check value.

#The where:in Filter

The where:in accepts an arbitrary comment property to check, and a list of values to check against. The filter will return only those comments whose property value exists in the provided list of values. The following example will return only those comments that have either six or ten revisions:

1{{ meerkat:responses filter="where:in(revision_count, 6, 10)" }}
2 
3 {{ comments }}
4 <!-- Render your comment thread here. -->
5 {{ /comments }}
6 
7{{ /meerkat:responses }}

Notice that we didn't have to do anything special with the second and third arguments. Meerkat will automatically collect all input arguments after the first one and assume they should be part of the list.

You may also wrap input in single quotes:

1{{ meerkat:responses filter="where:in(revision_count, `6`, `10`)" }}
2 
3 {{ comments }}
4 <!-- Render your comment thread here. -->
5 {{ /comments }}
6 
7{{ /meerkat:responses }}

The inline syntax with Antlers currently does not support (or handle well) input that contains quotes or commas inside strings. For example, if you wanted to provide a list of names that contains "Alice's, Bob's" you would need to use Custom Variable Input in order to accomplish this.

The following example demonstrates how to supply complicated input (input with either commas or quotes):

1{{ meerkat:responses filter="where:in(name, $myInput)" }}
2 
3 {{ comments }}
4 <!-- Render your comment thread here. -->
5 {{ /comments }}
6 
7{{ /meerkat:responses }}

In the meerkat/filters.php helper file:

1<?php
2 
3use Stillat\Meerkat\Support\Facades\Comments;
4 
5Comments::resolve('myInput', function () {
6 return [
7 'Supply complicated input, with commas, this way',
8 'This method also supports quotes: \''
9 ];
10});

#The not:where:in Filter

The not:where:in filter is the logical opposite of the where:in filter. It accepts an arbitrary comment property to check, and a list of values to check against. The filter will return only those comments whose property value does not exist in the provided list of values. The following example will return only those comments that do not have a revision count of six or ten:

1{{ meerkat:responses filter="not:where:in(revision_count, 6, 10)" }}
2 
3 {{ comments }}
4 <!-- Render your comment thread here. -->
5 {{ /comments }}
6 
7{{ /meerkat:responses }}

The inline syntax with Antlers currently does not support (or handle well) input that contains quotes or commas inside strings. For example, if you wanted to provide a list of names that contains "Alice's, Bob's" you would need to use Custom Variable Input in order to accomplish this.

The following example demonstrates how to supply complicated input (input with either commas or quotes):

1{{ meerkat:responses filter="not:where:in(name, $myInput)" }}
2 
3 {{ comments }}
4 <!-- Render your comment thread here. -->
5 {{ /comments }}
6 
7{{ /meerkat:responses }}

In the meerkat/filters.php helper file:

1<?php
2 
3use Stillat\Meerkat\Support\Facades\Comments;
4 
5Comments::resolve('myInput', function () {
6 return [
7 'Supply complicated input, with commas, this way',
8 'This method also supports quotes: \''
9 ];
10});

Some absolutely amazing
people

The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.