Learndash Course List

I am trying to pull a list of all courses that a user in a group is enrolled in. This is what I have so far. It is pulling the group members, but it’s pulling a list of all my enrolled courses instead of just the ones they are enrolled in.

<Loop query=group_users>
  <Note>Save user ID for current Loop Iteration</Note>
  <Set group_user_id><Field id /></Set>
    <a class="user-link text-bold" href="{Field archive_url}">
      <div class="mr-2 avatar text-xs"><Field avatar size=32 /></div>
      <span><Field display_name /></span>
    </a>
    <Note>Loop through each course</Note>
    <Loop query=all_courses user_id="{Get group_user_id}" enrolled=true>
      <Note>Set up math variable</Note>
      <Math>completed_lessons = 0</Math>
      <p><Field title /></p>
    </Loop>
  </Loop>

Just a guess, but try this maybe? Use student instead of user_id and learndash_course instead of all_courses here?

  <Loop type=learndash_course student="{Get group_user_id}" enrolled=true>

Docs for Course since learndash_course is the one that takes in the enrolled param

enrolled - Current user is enrolled

And then try student instead of user id?

student - Student ID(s) or “current” for the current student

I’m also not entirely sure about your query=group_users? In the docs, all I see is learndash_group_userGroup User | Loops & Logic

You might need to do a query for group learndash_group and then pull in the users from that?

1 Like

Maybe something like this?

<Loop type=learndash_group>
  <Set group_id><Field id /></Set>
  
  <Loop field=users>
    <Set user_id><Field id /></Set>
    <a class="user-link text-bold" href="{Field archive_url}">
      <div class="mr-2 avatar text-xs"><Field avatar size=32 /></div>
      <span><Field display_name /></span>
    </a>
    
    <Loop type=learndash_course student="{Get user_id}" enrolled=true>
      <Math>completed_lessons = 0</Math>
      <p><Field title /></p>
    </Loop>
  </Loop>
</Loop>
1 Like

Hey @jenn looks like @zack has got it!

Using the Loop Type learndash_group should help you with what you wanted to achieve. You can check out Learndash - Group Documentation for more details but this integration requires the Loops & Logic Pro plugin. Let us know if you need more help. Thanks!

I tried this and it didn’t pull what I needed. It pulled all users and all courses whether they were enrolled or not, which means it is probably pulling my info still. I ended up creating a shortcode to pull what I needed though.