Check user role in the user loop and sample lessons display

Greetings,

I am working on two blocks and got a little stuck with two markup.

  1. I am working on a users directory and the first one is to test the user_role inside the loop using the if statement. I’ve tried several different comparison like the following markup:
    <If check=user_role includes value=administrator >
    But it appears as though the comparison is done on the currently logged in user and not the user in the loop? I am guessing that I missed something in the markup to get it to loop through the users in the loop instead?

  2. I am working on displaying the title of all sample LearnDash lessons on the site. From looking at other examples, it appears as though it is as simple as doing something like the following:

      <Loop type=learndash_lesson  fields="lesson_is_sample">
         <h4><Field title /></h4>
       </Loop> 
    

However I am not having much luck there.

Can you please guide me as to some concepts I am missing?

Thank you in advance!

Hello, nice to see you here in the forums.

For 1, the following condition should work as expected:

<If user_role includes value=administrator>

The attribute check is for a different purpose, it compares the given text (“user_role” as is).

For 2, I looked into how to query for all sample lessons. It seems LearnDash doesn’t support such a loop query directly, but it’s still possible to filter lessons by using If.

<Loop type=learndash_lesson>
  <If field=lesson_is_sample>
    <h4><Field title /></h4>
  </If>
</Loop>

It’s kind of inefficient to get all lessons and filter, so this might get slow if the site has thousands of lessons in total, for example.

Hello @eliot,

Many thanks for your reply on this!

  1. I had the chance to try implementing your suggestion, but for some reason it is not working out well. The following if statement return “Educator” for all users despite their different roles.

     <If user_role includes value="administrator">
           <p>Educator</p> 
     <Else />
           <p>Student</p>
      </If>
    
  2. I see that the markup works as I expected, so thank you for that. In regards to the number of lessons on the site, can the issue of slowing down the site be rectified by using paginations? Or will the loop query all lessons and the filter out the samples?

We discovered on a call with Kendell today that the correct way to get the role is “roles” rather than “user_role” so that seems to be the issue here!

Many thanks for the support guys. The solution would look like this.

<If field=roles includes value="administrator">
       <p>Educator</p> 
 <Else />
       <p>Student</p>
  </If>
1 Like