Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress trigger 404

How can I trigger a 404 template to show up ? I have done the following ...

$_escaped_fragment_ = $_REQUEST['_escaped_fragment_'];
$post = ( get_page_by_path($_escaped_fragment_,'','brands' ) );
if(!empty($post) ){
    setup_postdata($post);
    the_title();
    get_template_part('loop');
    wp_reset_postdata();
}else{
    get_404_template();//not working
    include( get_query_template( '404' ) );//not working...
}
like image 721
Lee Avatar asked Oct 29 '12 15:10

Lee


People also ask

How do I enable 404 in WordPress?

In the left-hand menu of the WordPress Admin Dashboard, go to Appearance -> 404 Error Page. Select the page you have just customized as your 404 page and set it as 404-error page that'll be displayedappear by default, when users land on a broken link: Click Save Changes and that's it.

Why am I getting a 404 error on my WordPress?

WordPress 404 errors usually occur when you have removed certain pages from your website and haven't redirected them to your live pages. Sometimes, these errors may also occur when you have changed a URL of a specific page.


1 Answers

How about this? this should work.

status_header(404);
include( get_404_template() );
exit;

instead of this

get_404_template();//not working
include( get_query_template( '404' ) );//not working...
like image 132
Welling Avatar answered Sep 28 '22 07:09

Welling