Skip to content

Instantly share code, notes, and snippets.

@cameronjonesweb
Created May 1, 2021 01:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cameronjonesweb/9114814ee0b52c865de3f97d499295ed to your computer and use it in GitHub Desktop.
Save cameronjonesweb/9114814ee0b52c865de3f97d499295ed to your computer and use it in GitHub Desktop.
Fix 404 pages returning true for have_posts if permalinks have a prefix ie "/news/%postname/"
<?php
function cameronjonesweb_404_fix() {
global $wp_query;
if ( $wp_query->is_404 ) {
$wp_query->posts = array();
$wp_query->current_post = 0;
$wp_query->post = null;
}
}
add_action( 'template_redirect', 'cameronjonesweb_404_fix' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment