Filter uncanny-toolkit-pro

uo_course_category_cats

Filters arguments for fetching course categories before they are retrieved, allowing modification of category retrieval.

add_filter( 'uo_course_category_cats', $callback, 10, 3 );

Description

Filters the arguments used to retrieve course categories before they are fetched. Developers can modify the `$get_categories_args` array to customize category retrieval, influencing the `$type`, `orderby`, `order`, and `hide_empty` parameters. This hook is applied before fetching categories for display.


Usage

add_filter( 'uo_course_category_cats', 'your_function_name', 10, 3 );

Parameters

$get_categories_args (mixed)
This parameter contains an array of arguments used to retrieve course categories.
$type (mixed)
This parameter holds an array of arguments used to query WordPress categories.
$atts (mixed)
This parameter specifies the taxonomy being queried for course categories.

Return Value

The filtered value.


Examples

/**
 * Example function to modify the course category arguments before fetching categories.
 * This could be used to exclude certain categories or add custom arguments.
 *
 * @param array $get_categories_args The arguments passed to get_categories().
 * @param string $type The taxonomy type being requested (e.g., 'category', 'post_tag').
 * @param array $atts The attributes used to generate the output.
 * @return array The modified arguments for get_categories().
 */
add_filter( 'uo_course_category_cats', function( $get_categories_args, $type, $atts ) {
	// Example: Exclude a specific category slug if it's not already excluded.
	// Replace 'exclude-this-slug' with the actual slug you want to exclude.
	if ( ! isset( $get_categories_args['exclude'] ) ) {
		$get_categories_args['exclude'] = array();
	}
	// Ensure exclude is an array
	if ( ! is_array( $get_categories_args['exclude'] ) ) {
		$get_categories_args['exclude'] = explode( ',', $get_categories_args['exclude'] );
	}
	$get_categories_args['exclude'][] = 'exclude-this-slug';

	// Example: If $atts contains a specific key, change the orderby.
	if ( isset( $atts['sort_by'] ) && $atts['sort_by'] === 'date' ) {
		$get_categories_args['orderby'] = 'date';
		$get_categories_args['order']   = 'DESC';
	}

	return $get_categories_args;
}, 10, 3 );

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/classes/show-all-courses.php:439

$get_categories_args = array(
			'taxonomy'   => $type,
			'type'       => 'sfwd-courses',
			'orderby'    => 'name',
			'order'      => 'ASC',
			'hide_empty' => false,
		);
		$categories          = apply_filters( 'uo_course_category_cats', get_categories( $get_categories_args ), $type, $atts );

		if ( $type === 'category' ) {
			$filter .= '<div class="uo-ultp-grid-container uo-ultp-grid-container--category-dropdown">';
			$filter .= '<div class="uo-grid-wrapper" id="uo_categorydropdown">';
			$filter .= '<form method="get">
                                    <label for="uo_categorydropdown_select">' . esc_html__( 'Category', 'uncanny-pro-toolkit' ) . '</label>
                                    <select id="uo_categorydropdown_select" name="catid" onChange="jQuery('#uo_categorydropdown form').submit()">';

Scroll to Top