[wp-hackers] Throw 404 error via plugin

Andrew Nacin wp at andrewnacin.com
Wed Jan 12 06:24:28 UTC 2011


On Tue, Jan 11, 2011 at 10:01 PM, Ryan Bilesky <rbilesky at gmail.com> wrote:

> So I am working on a plugin where I want to selectivly throw a 404 error.
>
> I try header() and this sets the http header to show a not found error, but
> I get the browsers default 404 error page.
>
> I try including the 404.php template file but while it looks like a 404
> error to the user, the http header status shows 200 ok.
>
> I try using both methods together again no luck,.  I want the http status
> code to show 404 AND to use the 404.php template to show the user.  How
> does
> the core do this?


The template file doesn't have to do with the headers. You'll want to
trigger 404 headers via status_header('404') and the 404 template via
$wp_query->set_404(). But a lot of this depends on what exactly you're
trying to do.

Nacin


More information about the wp-hackers mailing list