Skip to content

Instantly share code, notes, and snippets.

@askwpgirl
Created November 29, 2025 23:08
Show Gist options
  • Select an option

  • Save askwpgirl/327d2f266dae414d41d002107deef1ee to your computer and use it in GitHub Desktop.

Select an option

Save askwpgirl/327d2f266dae414d41d002107deef1ee to your computer and use it in GitHub Desktop.
Elementor Custom Query: Lessons for Current Course
<?php
/**
* Elementor Custom Query: Lessons for Current Course
*/
add_action( 'elementor_pro/posts/query/course_lessons', function( $query ) {
// Get current course ID (assuming this runs on the single course page)
$course_id = get_the_ID();
if ( ! $course_id ) {
return;
}
// Make sure we’re only running this on the front end main query for the widget
if ( ! $query->is_main_query() ) {
return;
}
// Base args to fetch lessons
$args = [
'post_type' => 'sfwd-lessons', // adjust if your lessons CPT is different
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC',
'meta_query' => [
[
'key' => 'course_id', // adjust to your LMS’s meta key
'value' => $course_id,
],
],
];
// Apply our custom args to Elementor’s query
foreach ( $args as $key => $value ) {
$query->set( $key, $value );
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment