actnow
Active member
- Oct 19, 2019
- 126
- 140
- 43
I am using Masterstudy theme, when the course is published as draft we can only view the course details and when we go to lessons we get 404
The draft preview URL is like domain.com/?post_type=stm-courses&p=882&preview=true
The lesson URL is like domain.com/?post_type=stm-courses&p=882882-13 (404)
The problem seems to be premalink
If the course is published
The live URL is like domain.com/courses/web-coding-and-apache-basics/
The lesson URL is like domain.com/courses/web-coding-and-apache-basics/882-13
I tried to add a function
It does not seem to work, any help would be appreciated
The draft preview URL is like domain.com/?post_type=stm-courses&p=882&preview=true
The lesson URL is like domain.com/?post_type=stm-courses&p=882882-13 (404)
The problem seems to be premalink
If the course is published
The live URL is like domain.com/courses/web-coding-and-apache-basics/
The lesson URL is like domain.com/courses/web-coding-and-apache-basics/882-13
I tried to add a function
Code:
function draft_permalink( $post_id, $current_permalink) {
$post = get_post( $post_id );
if (in_array($post->post_status, array('draft', 'pending', 'auto-draft'))) {
$my_post = clone $post;
$my_post->post_status = 'published';
$my_post->post_name = sanitize_title($my_post->post_name ? $my_post->post_name : $my_post->post_title, $my_post->ID);
$permalink = get_permalink($my_post);
} else {
$permalink = $current_permalink;
}
return $permalink;
}
function course_wp_link_query( $results, $query ) {
foreach ( $results as &$result ) {
$result['permalink'] = draft_permalink( $result['ID'], $result['permalink'] );
}
return $results;
}
add_filter( 'wp_link_query', 'course_wp_link_query' );
It does not seem to work, any help would be appreciated