首页 > 解决方案 > 将自定义帖子类型“问题”的永久链接更改为帖子 ID

问题描述

我需要显示这样的问题,从 quizzes/quiz-1/question-1 到 quizzes/quiz-1/%question-post-id%/

我改变了 $permalink = $permalink 。$question_id; 但它不起作用。

任何帮助将不胜感激。我花了几天时间解决这个问题。

/**
* 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 );
}

标签: phpwordpress

解决方案


推荐阅读