?How to get associated lessons of courses from Tutor LMS ?

WordPress
16 September, 2021 02:46:34
fabcoo
Topics: 2
Messages: 6
Hi,

I'm currently trying to extract data from an LMS plugin called Tutor LMS, which can generate courses, with associated lessons. I'm able to get a lot of data from the plugin, with keys like "_tutor_course_requirements" or "_tutor_course_benefits", but I don't see any key linked to associated lessons. From what I gathered from the database, lessons are a different post type, associated by a parent post system to the course it is attached to (for example, the value of the parent post id of all lessons associated to my course is 31)

My question is, even if the template is set to a specific post type (course), is it possible to gather multiple data from a different post type (lesson) if there is a value in common (parent post id) ? Also I tried to see which key of the course can generate the parent post id of the lesson, but I didn't find it in the proposed fields, is there a conditionnal system that can help me here?

Thanks a lot for the answers, and I'll be glad to help if you need any more information!
16 September, 2021 04:46:31
fabcoo
Topics: 2
Messages: 6
Just to extend, after more research I found that the output of the course topics is rendered via the function tutor_course_topics() in the template, is it possible to stock the HTML output in a key by a custom function, so it can be show as an HTML object on the PDF template?
16 September, 2021 10:16:44
E2Pdf
Support
Topics: 7
Messages: 3335
Hi,

As we understand you connected E2Pdf Template to "Courses". Unfortunately related post data is still under development and beta test, so it's not yet documented, however here is possible solutions:

You need to update plugin to RC Version (1.16.27) by following instruction here: https://e2pdf.com/support/desk/how-to-update-plugin-to-rc-release-candidate-version-from-e2pdf-com

===============================================
Possible Solutions:
===============================================

1. You can use "[e2pdf-foreach]" shortcode along with "[e2pdf-wp-posts]": https://codeshare.io/3APEXB.

It will iterate over child posts of course to get "topics" and after this it will iterate over "topics" to get "lessons". You can see that it's possible to use default "[e2pdf-wp]" shortcode inside "[e2pdf-foreach]" iteration. If it will fit your needs and you will need different order or some additional conditions, fill free to ask as we do not yet have documentation for current shortcodes due the "beta" stage.

P.S. It's also recommended to "Disable WYSIWYG Editor" on E2Pdf HTML object to avoid breaking "HTML" tags due verification by WYSIWYG Editor via "Right Mouse Click" -> "Properties"

OR

2. You can create own shortcode via functions.php as: https://codeshare.io/gLe3jB and use needed PHP functions to generate needed output. Inside E2Pdf Template you must be able to use it as follows: [myshortcode id="[e2pdf-dataset]"]

* [e2pdf-dataset] - will be converted to your Post ID for which E2Pdf generates PDF (in your way it must Course ID)

P.P.S. Both solutions will require RC Version.

We remain at your service.
We would really appreciate your feedback at WordPress.org!
17 September, 2021 00:23:42
fabcoo
Topics: 2
Messages: 6
Thanks a lot for the answers, I'll check this today and get back to you!
17 September, 2021 06:06:47
fabcoo
Topics: 2
Messages: 6
I tested your code, and it worked great! Now I have all the listing of topics and lessons associated, and correctly linked to the course, thanks a lot!

I used your first snippet by the way, and I customized it a little in the "properties" textarea to get the HTML output I wanted, and it looked like that :

[e2pdf-foreach shortcode="e2pdf-wp-posts" post_parent="[e2pdf-dataset]" post_type="topics" order="ASC" numberposts="999"]<h3><strong>[e2pdf-wp key="post_title" id="[e2pdf-foreach-value path='ID']"]</strong></h3><ul>[e2pdf-foreach-1 shortcode="e2pdf-wp-posts" post_parent="[e2pdf-foreach-value path='ID']" post_type="lesson" order="ASC" numberposts="999"]<li>[e2pdf-wp key="post_title" id="[e2pdf-foreach-value-1 path='ID']"]</li>[/e2pdf-foreach-1]</ul><br />[/e2pdf-foreach]

Thanks again for the quickness and precision of your answer, your plugin is really amazing!