I created custom query var. So I need to include 404 page if query var not exists.

function add_rewrites(){
add_action( 'init', 'add_rewrites' );

function add_custom_query_var( $vars ){ 
$vars[] = "sub_pages"; 
return $vars; 
add_filter( 'query_vars', 'add_custom_query_var' );

For example:
if( get_query_var( ‘sub_pages’ ) == ” ){
//Normal Content
}elseif( get_query_var( ‘sub_pages’ ) == ‘example’ ){
//Example Content
//Include or Load 404

Read more here: including 404 page in post template


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: