Reputation: 704
I looked all over the Learndash documentation but I'm unable to find a function to obtain the course title from a course id. Does anyone know how to do this or have some sample code ?
Logged in users can see the certificates they've earned so that they can click the link and download any certificate. Below is the code I currently have. I get the list of currently enrolled courses into $arr1
array. This is an array of Course IDs
. I'm going through this array and for any course that is completed
, I'm allowing user a link to download the course.
Currently, I can get the course download link using function learndash_get_course_certificate_link
. However, I want to display the name of the course (course title) in the text of the a href.
The text DOWNLOAD YOUR PROJECT MANAGEMENT CERTIFICATE
, DOWNLOAD YOUR ACCOUNTING CERTIFICATE
, etc is what I want to display for each certificate.
$current_user = wp_get_current_user();
$arr1 = learndash_get_user_course_access_list($current_user->ID );
foreach ($arr1 as $value)
{
$val = learndash_course_status($value);
if ($val == "Completed")
{
$certificate_link = learndash_get_course_certificate_link($value);
echo '<a href="'.$certificate_link.'">DOWNLOAD YOUR PROJECT MANAGEMENT CERTIFICATE</a>';
echo '<br>';
}
}
Upvotes: 2
Views: 3460
Reputation: 79
thanks for your solution it helped me to get the title of the course, but in my case, I don't have an id of the course (because I make the same course page (as style ) for all courses so I want to display the title dynamically) and in my case, I have generated a new shortcode for the title so I can use it wherever I want. this is the code :
add_shortcode( 'lmscoder-course-title', 'lmscoder_course_title' );
function lmscoder_course_title() {
// go away if LearnDash isn't active
if ( ! function_exists( 'learndash_get_course_meta_setting' ) ) {
return;
}
//get course id
$id = learndash_get_course_id();
$course = get_post($id);
// return the title
return $course->post_title;
}
hope it helps.
Upvotes: 1
Reputation: 704
OK, I found the answer. All I have to do is call the php function: get_post(...). This gets me the title of the course:
$course = get_post($course_id);
echo $course->post_title;
Upvotes: 4