posts_groupby WordPress Filter Hook

The posts_groupby hook is one of the most important hooks in WordPress. It allows you to group your posts by a certain criteria. This can be very useful if you want to display a certain number of posts per page or if you want to group your posts by a certain taxonomy.

apply_filters_ref_array( 'posts_groupby', string $groupby, WP_Query $query ) #

Filters the GROUP BY clause of the query.


Parameters

$groupby

(string)The GROUP BY clause of the query.

$query

(WP_Query)The WP_Query instance (passed by reference).


Top ↑

More Information

  • If you come with MySQL knowledge, the GROUP BY clause is pretty useless without the ability to modify the SELECT statement.
  • There is no SELECT filter since the query is supposed to return only the post data. The GROUP BY clause is set only when there are Custom Field Parameters for querying by post meta or Taxonomy Parameters for querying by taxonomy.
  • The default posts_groupby is set to {$wpdb->posts}.ID, which means that even if there are multiple results because of multiple meta and taxonomy, they are grouped together by the post id.

Top ↑

Source

File: wp-includes/class-wp-query.php

View on Trac



Top ↑

Changelog

Changelog
VersionDescription
2.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More