I have a couple of pages that are populated with data from non-Wordpress tables in my database. https://pageURL/?asi_id=12345 causes the DB-lookup to get the correct data. If someone uses the wrong query-string I want a 404 error generated. I am at a point long after the headers have been generated when I discover the issue. I have tried several code fragments from this forum and others. They cause the "404-template" to be displayed by the status code is still 200 and not 404. I suspect that Google wants the correct status code.
Any ideas how I can force the error at this point in WP's loop?