Create a function which will check your condition. If the condition is met, set $wp_query->is_404 to true.

Then call that function like add_action(‘template_redirect’, ‘functionName’);

	function functionName()
	{
            global $wp_query, $post;
            if (condition here) {
                    $wp_query->is_404 = true;
            }
	}

        add_action('template_redirect', 'functionName');

 

 

Leave a Reply