Skip to content

Instantly share code, notes, and snippets.

@marcovega
Created November 22, 2015 03:14
Show Gist options
  • Save marcovega/d0eed9e0108c946ada96 to your computer and use it in GitHub Desktop.
Save marcovega/d0eed9e0108c946ada96 to your computer and use it in GitHub Desktop.
Shortcode to list all lessons within a course in Woo Sensei
<?php
/**
* List lessons by course
*
* Generates the shortcode that outputs the list of the lessons for a given course.
*
* @return string The HTML Layout output of the Course Lessons.
*/
function lessons_shortcode_func(){
$args = [
'post_type' => 'lesson',
'posts_per_page' => 99,
'orderby' => 'meta_value_num',
'meta_key' => '_order_51',
'order'=> 'ASC',
'meta_query' => [
'key' => '_lesson_course',
'value' => '51'
]
];
$lessons = get_posts( $args );
$output = null;
foreach($lessons as $lesson){
$output .= $lesson->post_title . '<br>';
}
return $output;
}
add_shortcode( 'list-lessons', 'lessons_shortcode_func' );
@kakoma
Copy link

kakoma commented Jun 13, 2018

Thanks for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment