将自定义帖子类型的固定链接更改为帖子ID或任意随机数一次

时间:2018-09-13 作者:Talha Hameed

我需要显示以下问题,从测验/测验-1/问题-1到测验/测验-1/%问题帖子id%/

我已更改$permalink=$permalink$问题\\u 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 );
 }

1 个回复
SO网友:Krishna Joshi

如果需要简单的解决方案,可以尝试Custom Post Type Permalinks 插件。

希望这有帮助。

结束