Getting 404 error while rendering question page.
Thanks for your reply Rahul.
I tried to flush the rewrite rule after new question hook where I am changing the parent Id for the question, but its not working for me. I got the 404 error.
In rewrite.php there is following function:
public static function add_query_var($wp) {
if ( ! empty( $wp->query_vars['question_name'] ) ) {
$wp->set_query_var( 'ap_page', 'question' );
$question = get_page_by_path( sanitize_title( $wp->query_vars['question_name'] ), 'OBJECT', 'question' );
if ( $question ) {
$wp->set_query_var( 'question_id', $question->ID );
}
// Rediret to 404 page if question does not exists.
else {
global $wp_query;
$wp_query->set_404();
status_header( 404 );
get_template_part( 404 );
exit();
}
}
if ( ! empty( $wp->query_vars['ap_user'] ) ) {
$user = get_user_by( 'login', sanitize_text_field( urldecode( $wp->query_vars['ap_user'] ) ) );
if ( $user ) {
$wp->set_query_var( 'ap_user_id', $user->ID );
}
}
}In this get_page_by_path return null, if I set the parent id for the question.