uo_tincanny_reporting_list_of_course_ids
Filters the list of course IDs used in Tincanny reporting to customize which courses are included.
add_filter( 'uo_tincanny_reporting_list_of_course_ids', $callback, 10, 1 );
Description
Allows modification of the course IDs used in Tincanny reporting. Developers can filter this list to include or exclude specific courses from reports generated for users and groups, ensuring data accuracy and relevance. Defaults to an empty array, meaning all courses are considered unless filtered.
Usage
add_filter( 'uo_tincanny_reporting_list_of_course_ids', 'your_function_name', 10, 1 );
Parameters
-
$course_list(mixed) - This parameter contains a list of course IDs that will be used for reporting.
Return Value
The filtered value.
Examples
/**
* Filter the list of course IDs to only include courses from a specific category.
*
* This example demonstrates how to modify the default list of course IDs
* provided by the uo_tincanny_reporting_list_of_course_ids filter.
*
* @param array|int|null $course_list The original list of course IDs.
* @return array The filtered list of course IDs.
*/
add_filter( 'uo_tincanny_reporting_list_of_course_ids', function( $course_list ) {
// Ensure $course_list is an array for easier manipulation.
if ( ! is_array( $course_list ) ) {
$course_list = (array) $course_list;
}
// If the list is empty, no need to filter.
if ( empty( $course_list ) ) {
return $course_list;
}
// Define the category slug you want to filter by.
$target_category_slug = 'featured-courses';
// Get all course IDs belonging to the target category.
$args = array(
'post_type' => 'sfwd-courses',
'posts_per_page' => -1, // Get all matching posts
'tax_query' => array(
array(
'taxonomy' => 'sfwd-courses_category', // Assuming this is the taxonomy for LearnDash courses
'field' => 'slug',
'terms' => $target_category_slug,
),
),
'fields' => 'ids', // Only retrieve IDs
);
$category_course_ids = get_posts( $args );
// If no courses are found in the category, return an empty array.
if ( empty( $category_course_ids ) ) {
return array();
}
// Intersect the original course list with the category course IDs to get courses present in both.
$filtered_course_ids = array_intersect( $course_list, $category_course_ids );
// Return the filtered list of course IDs.
return array_values( $filtered_course_ids ); // Re-index array keys.
}, 10, 1 );
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/reporting/learndash/courses-users-report/build-report-data.php:1030
$restrict_group_leader_associated_posts,
0,
),
4.2,
'uo_tincanny_reporting_list_of_course_ids'
);
$course_list = apply_filters( 'uo_tincanny_reporting_list_of_course_ids', $course_list );
$rearranged_course_list = array();
$course_posts = array();
if ( ! empty( $course_list ) ) {
$course_posts = get_posts([
'post_type' => 'sfwd-courses',
'post__in' => $course_list,
'posts_per_page' => 99999, // phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_posts_per_page