1

I need to display questions like this from quizzes/quiz-1/question-1 to quizzes/quiz-1/%question-post-id%/

I have changed $permalink = $permalink . $question_id; but it does not work.

Any help would be greatly appreciated. I have spent days going through the problem.

/**
* Get question permalink from it’s ID.
* If permalink option is turn on, add name of question
* into quiz permalink. Otherwise, add it’s ID into
* query var.
*
* @param int $question_id
*
* @return string
*/
public function get_question_link( $question_id = null ) {
$course = LP_Global::course();
$permalink = $course->get_item_link( $this->get_id()   );
if ( ” != get_option( ‘permalink_structure’ ) && get_post_status( $this>get_id() ) != ‘draft’ ) {
if ( get_post_type( $question_id ) === LP_QUESTION_CPT ) {
$question_name = get_post_field( ‘post_name’,  $question_id );
$permalink = $permalink . $question_name;
}
} else {
$permalink = add_query_arg( array( ‘question’, $question_id ), $permalink );
}

// @deprecated
$permalink = apply_filters( ‘learn_press_quiz_question_permalink’, 
$permalink, $question_id, $this );

return apply_filters( ‘learn-press/quiz/question-permalink’, $permalink, 
$question_id, $this->get_id() );
}

/*
* Get question url in a quiz for user
*
* @param int the ID of a quiz
* @param int the ID of question – default is current question of quiz user 
* is doing
* @param int the ID of user – default is current user
*
* @return string
*/
function learn_press_get_user_question_url( $quiz_id, $current_question_id = 0, $user_id = 0 ) {
if ( ! $current_question_id ) {
$current_question_id = learn_press_get_current_question( $quiz_id, $user_id 
);
}
$permalink = get_the_permalink( $quiz_id );
if ( $current_question_id && get_post_type( $current_question_id ) == ‘lp_question’ ) {
$question_name = get_post_field( ‘post_name’, $current_question_id );
if ( ” != get_option( ‘permalink_structure’ ) ) {
$permalink .= $question_name;
} else {
$permalink = add_query_arg( ‘question’,  $question_name, $permalink );
}
}
$permalink = trailingslashit( $permalink );

return apply_filters( ‘learn_press_quiz_question_url’, $permalink, $quiz_id, $current_question_id, $user_id );
 }

1 Answer 1

0

If you need a easy solution, you can try out the Custom Post Type Permalinks plugin.

Hope this helps.

1
  • I tried this plugin but it is not working. i have written the code above which itself tell the condition to use post id if permalink structure is not setup Sep 14, 2018 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.