Filter hook 'get_terms_fields'

in WP Core File wp-includes/class-wp-term-query.php at line 699

View Source

get_terms_fields

Filter Hook
Description
Filters the fields to select in the terms query. Field lists modified using this filter will only modify the term fields returned by the function when the `$fields` parameter set to 'count' or 'all'. In all other cases, the term fields in the results array will be determined by the `$fields` parameter alone. Use of this filter can result in unpredictable behavior, and is not recommended.

Hook Information

File Location wp-includes/class-wp-term-query.php View on GitHub
Hook Type Filter
Line Number 699

Hook Parameters

Type Name Description
string[] $selects An array of fields to select for the terms query.
array $args An array of term query arguments.
string[] $taxonomies An array of taxonomy names.

Usage Examples

Basic Usage
<?php
// Hook into get_terms_fields
add_filter('get_terms_fields', 'my_custom_filter', 10, 3);

function my_custom_filter($selects, $args, $taxonomies) {
    // Your custom filtering logic here
    return $selects;
}

Source Code Context

wp-includes/class-wp-term-query.php:699 - How this hook is used in WordPress core
<?php
 694  		 *
 695  		 * @param string[] $selects    An array of fields to select for the terms query.
 696  		 * @param array    $args       An array of term query arguments.
 697  		 * @param string[] $taxonomies An array of taxonomy names.
 698  		 */
 699  		$fields = implode( ', ', apply_filters( 'get_terms_fields', $selects, $args, $taxonomies ) );
 700  
 701  		$join .= " INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id";
 702  
 703  		if ( ! empty( $this->query_vars['object_ids'] ) ) {
 704  			$join    .= " INNER JOIN {$wpdb->term_relationships} AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id";

PHP Documentation

<?php
/**
		 * Filters the fields to select in the terms query.
		 *
		 * Field lists modified using this filter will only modify the term fields returned
		 * by the function when the `$fields` parameter set to 'count' or 'all'. In all other
		 * cases, the term fields in the results array will be determined by the `$fields`
		 * parameter alone.
		 *
		 * Use of this filter can result in unpredictable behavior, and is not recommended.
		 *
		 * @since 2.8.0
		 *
		 * @param string[] $selects    An array of fields to select for the terms query.
		 * @param array    $args       An array of term query arguments.
		 * @param string[] $taxonomies An array of taxonomy names.
		 */
Quick Info
  • Hook Type: Filter
  • Parameters: 3
  • File: wp-includes/class-wp-term-query.php
Related Hooks

Related hooks will be displayed here in future updates.