For my bit it was little complicated because course category have to correspond to specific page and , so my hierarchy is like domain.com/page/course-category/course/lesson(quiz/assignment)
where every slug after domain name is dynamically set. So I had two problems and only solution was to use permalink manager.
So now every top-level course category slug has same slug as page which we want to display instead of category archive. ex.: domain.com/page(category-slug)/…
other problem was to set lesson/quizes/etc. url to correspond to this newly dynamic url of their respective course. And that where permalink manager comes in handy.
As I didn’t want to change tutor plugin rewrite rules as it would take to much time to go through all the code so I created hook permalink_manager_filter_default_post_uri as this:
function tutor_parent_course_tag( $default_uri, $native_slug, $post ) {
if ( in_array( $post->post_type, array( 'lesson', 'tutor_quiz', 'tutor_assignments' ) ) ) {
$post_id = $post->ID;
$course_id = null;
if ( $post->post_type === 'lesson' ) {
$course_id = get_post_meta( $post_id, '_tutor_course_id_for_lesson', true );
} else if ( $post->post_type === 'tutor_quiz' ) {
$course_id = get_post($post->post_parent)->post_parent;
} else if ( $post->post_type === 'tutor_assignments' ) {
$course_id = get_post_meta( $post_id, '_tutor_course_id_for_assignments', true );
}
$course_uri = '';
if ( $course_id ) {
$course = get_post( $course_id );
if ( $course ) {
$course_uri = get_relative_permalink( get_permalink( $course_id ) );
}
}
$default_uri = str_replace( '%parent_course%', $course_uri, $default_uri );
return $default_uri;
}
return $default_uri;
}
add_filter( 'permalink_manager_filter_default_post_uri', 'tutor_parent_course_tag', 10, 3 );
And with permalink manager and yoast seo I even got the breadcrumbs to fully work
-
This reply was modified 4 years, 10 months ago by faremir.