WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a strange problem which I really do not understand:

My site has the page community and a sub-page called test. Permalink structure is set to /%postname%/

So the URLs for the pages are:

  • mysite.com/community
  • mysite.com/community/test

When I open the page "community/test" it is displayed correctly. But when I hit F5/refresh the test-page then I get an 404 error! When I refresh again I keep getting 404 errors, until I load a different page (e.g. front-page) and then go back to the test-page. Then the test page is displayed again on first request but on refresh I get a 404 again.

These are normal WordPress pages, no custom post-type etc. Also the WordPress installation is not using multi-site. And I do not know what is causing this issue...

share|improve this question
That is pretty bizarre. The standard procedure in WP when encountering odd behavior is to try disabling your plugins and test if the problem went away. If it did, you can start re-enabling plugins one-by-one until you isolate the cause. If you have anything special going on in your functions.php I would try removing that next if disabling plugins doesn't resolve your problem. – Matt Keys Jun 15 '13 at 2:18
I have a similar problem, did you finally found a solution? – Hubert Perron Jun 13 '14 at 14:41
up vote 0 down vote accepted

I never found the real reason for this issue. However this "bugfix" did solve the issue for me:

add_action( 'template_redirect', 'handle_strange_bug', 10 );

// "Fixes" the strange bug...
function handle_strange_bug() {
    global $post;

    $post_id = 123; // This is the post that makes problems.

    /* ===== Start of the bugfix.
     * If the $post->ID is not set, but the URL indicates we are on the problem-
     * page then do a redirect to an alternative URL for the page. After the
     * redirect we always had a valid $post->ID, so 
    if ( !isset($post->ID) ) {
        // The function is defined below.
        $my_url = get_current_url();

        if ( $my_url == get_permalink($post_id) )  {
            $good_url = site_url() . '?page_id=' . $post_id;
    // ===== End of the bugfix.

// Helper function. Returns the full URL of the current request.
function get_current_url() {
    if ( @$_SERVER['HTTPS'] == 'on' ) { 
        $page_url = 'https://'; 
    } else {
        $page_url = 'http://';
    $page_url .= @$_SERVER['SERVER_NAME'];
    if ( @$_SERVER['SERVER_PORT'] != '80' ) {
        $page_url .= ':' . @$_SERVER['SERVER_PORT'];
    $page_url .= @$_SERVER['REQUEST_URI'];
    // Remove the Query-string from the URL.
    if ( $pos_get = strpos($page_url, '?') ) { 
        $page_url = substr($page_url, 0, $pos_get);
    return $page_url;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.