Hi @kubalonek84,
You can use the PHP code below to hide some courses (by course ID) from the LifterLMS student dashboard page based on the specific WordPress user roles. In the code below, just replace $roles_to_exclude
with the array of WordPress user roles that you want. This array can have one or more items in it. You also need to replace $posts_to_exclude
with the array of course IDs.
function exclude_posts_for_roles($query) {
// Check if it is the main query and the user is logged in
if (is_admin() || !$query->is_main_query() || !is_user_logged_in()) {
return;
}
// Replace the array with your actual roles
$roles_to_exclude = array(
'student',
'editor'
);
// Replace the array with your actual post IDs to exclude
$posts_to_exclude = array(
98,
109
);
// Check if the user has any of the specified roles
$user_has_excluded_role = false;
foreach ($roles_to_exclude as $role) {
if (current_user_can($role)) {
$user_has_excluded_role = true;
break;
}
}
// If the user has any of the specified roles, exclude the specific posts
if ($user_has_excluded_role) {
$query->set('post__not_in', $posts_to_exclude);
}
}
add_action('pre_get_posts', 'exclude_posts_for_roles');