Advertisement
vapvarun

LD Quiz Redirect

Feb 19th, 2020
472
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.27 KB | None | 0 0
  1. add_filter( 'learndash_completion_redirect', 'wbcom_learndash_quiz_continue_link', 10, 2 );
  2. function wbcom_learndash_quiz_continue_link( $link, $post_id ) {
  3.     if( !empty( $post_id ) ){
  4.         /* Get the Course id from Quize id */
  5.         $course_id = get_post_meta( $post_id, 'course_id', true );
  6.         $args = array(
  7.                     'post_type'         => 'sfwd-quiz',
  8.                     'posts_per_page'    => 1,
  9.                     'order'             => 'DESC',
  10.                     'orderby '          => 'post_date',
  11.                     'meta_key'          => 'course_id',
  12.                     'meta_value'        => $course_id,
  13.                     'date_query' => array(
  14.                                     array(
  15.                                         'column' => 'post_date',
  16.                                         'after' => '24 hours ago',
  17.                                     ),
  18.                                 )
  19.                 );
  20.         /* Get the Number of Quize which is published within 24 hours from assigned course */
  21.         $course_quize = new WP_Query( $args );     
  22.         $course_quize_id = '';
  23.         if ($course_quize->have_posts()) {
  24.             while ( $course_quize->have_posts() ){
  25.                 $course_quize->the_post();
  26.                 $course_quize_id = get_the_ID();
  27.             }
  28.         }
  29.         /* Check latest published quize id and completion Quize id both are same then redirct to another page  */
  30.         if ( $course_quize_id == $post_id ) {
  31.             $link = 'https://google.com'; // Redirect latest quiz.
  32.         }
  33.         else{
  34.                 $link = 'https://wbcomdesigns.com/';
  35.             }
  36.     }
  37.     return $link;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement