-
-
Save iamcanadian1973/d89b3311af734443a7f09531a9a9db16 to your computer and use it in GitHub Desktop.
| <?php | |
| // Add group custom group attribute to check later | |
| add_filter( 'ld_course_list_shortcode_attr_defaults', function( $defaults ) { | |
| $defaults['mygroups'] = null; | |
| return $defaults; | |
| }, 10 ); | |
| // Filter course list by group id | |
| add_filter('learndash_ld_course_list_query_args', function( $filter, $atts ) { | |
| if ( ! is_user_logged_in() || ! $atts['mygroups'] ) { | |
| return $filter; | |
| } | |
| $user_id = get_current_user_id(); | |
| $group_ids = learndash_get_users_group_ids( $user_id ); | |
| $group_meta_id = []; | |
| if( empty( $group_ids ) ) { | |
| return $filter; | |
| } | |
| $meta_query = []; | |
| $meta_query[] = [ 'relation' => 'OR' ]; | |
| foreach( $group_ids as $group_id) { | |
| $group_meta_key = sprintf( 'learndash_group_enrolled_%d', $group_id ); | |
| $meta_query[] = array( | |
| 'key' => $group_meta_key, | |
| 'compare' => 'EXISTS' | |
| ); | |
| } | |
| $filter['meta_query'] = $meta_query; | |
| return $filter; | |
| }, 10, 2); |
These are just WordPress filters, you can add them anywhere in your theme. You can add them to your functions.php file.
Thanks for responding, I want to have a filter in learndash that helps me filter the courses according to the group to which the current user is subscribed. How do I make this filter appear in the fronted with the course grid?
Thanks
Thanks
Este no es un "filtro" real. Este es un filtro de WordPress. WordPress tiene acciones y filtros que alteran el código. Puedes usar el código si ayuda, pero no estoy seguro de que sea lo que estás buscando. De: mateolopera @.> Respuesta-A: iamcanadian1973 @.> Fecha: Miércoles, 30 de marzo de 2022 a las 9:45 AM A: iamcanadian1973 @.> Cc: Kyle Rumble @.>, Autor @.> Asunto: Re: iamcanadian1973/learndash-filter-courses-by-group.php @mateolopera comentado esta esencia.
...
____________________________________ ¿Cómo hago que este filtro aparezca en la parte delantera con la cuadrícula del curso? Gracias— Responda a este correo electrónico directamente, véalo en GitHubhttps://gist.github.com/d89b3311af734443a7f09531a9a9db16#gistcomment-4115891 o cancele la suscripciónhttps://github.com/notifications/unsubscribe-auth/AAAY66TZEBD24VD2R5TGJ7DVCSAJLANCNFSM5SCMPZRQ. Está recibiendo esto porque fue el autor del hilo. ID de mensaje: @.*>
Hi, where and how did you implement this file?
Thanks