Filters the GROUP BY clause of the query.
Parameters
Source
$groupby = apply_filters_ref_array( 'posts_groupby', array( $groupby, &$this ) );
Changelog
Version | Description |
---|---|
2.0.0 | Introduced. |
Filters the GROUP BY clause of the query.
$groupby = apply_filters_ref_array( 'posts_groupby', array( $groupby, &$this ) );
Version | Description |
---|---|
2.0.0 | Introduced. |
You must log in before being able to contribute a note or feedback.
Example migrated from Codex:
The code above will just set the GROUP BY clause whether or not, a taxonomy query or a meta query is present.
For example, say we have a custom table (for ratings) and we wish to filter the posts using data from this table (only show posts that have a 5 star rating).
We can use the posts_join filter to join the tables. If there are multiple entries in the ratings table, the join can return multiple results for the same post.
We can make sure that we only have one row per post (that has all the entries for the ratings) by setting the
GROUP BY
clause. Remember that in the default query,GROUP BY
clause is only set when there is a meta query or taxonomy query involved.