Filter hook 'get_the_categories'

in WP Core File wp-includes/category-template.php at line 98

View Source

get_the_categories

Filter Hook
Description
Filters the array of categories to return for a post.

Hook Information

File Location wp-includes/category-template.php View on GitHub
Hook Type Filter
Line Number 98

Hook Parameters

Type Name Description
WP_Term[] $categories An array of categories to return for the post.
int|false $post_id The post ID.

Usage Examples

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

function my_custom_filter($categories, $post_id) {
    // Your custom filtering logic here
    return $categories;
}

Source Code Context

wp-includes/category-template.php:98 - How this hook is used in WordPress core
<?php
  93  	 * @since 4.4.0 Added the `$post_id` parameter.
  94  	 *
  95  	 * @param WP_Term[] $categories An array of categories to return for the post.
  96  	 * @param int|false $post_id    The post ID.
  97  	 */
  98  	return apply_filters( 'get_the_categories', $categories, $post_id );
  99  }
 100  
 101  /**
 102   * Retrieves category name based on category ID.
 103   *

PHP Documentation

<?php
/**
	 * Filters the array of categories to return for a post.
	 *
	 * @since 3.1.0
	 * @since 4.4.0 Added the `$post_id` parameter.
	 *
	 * @param WP_Term[] $categories An array of categories to return for the post.
	 * @param int|false $post_id    The post ID.
	 */
Quick Info
  • Hook Type: Filter
  • Parameters: 2
  • File: wp-includes/category-template.php
Related Hooks

Related hooks will be displayed here in future updates.