jbrinley / WP-Router

Routes paths to callback functions in WordPress
108 stars 26 forks source link

Notice: Undefined property: WP_Query::$post #5

Open robadams22 opened 11 years ago

robadams22 commented 11 years ago

Hi,

Firstly thanks for a cracking plugin save me hours of coding. On my latest project I started getting the annoying Notice: Undefined property: WP_Query::$post. I always developed with debug to true and this bugged me for a while. In the end I tracked it down to the pre_get_posts call in WP_Router_Page.class.php around line 111. I implemented a simple check to solve my issue

public function edit_query( WP_Query $query ) { if($query->is_page()) { if ( isset($query->query_vars[self::QUERY_VAR]) ) { // make sure we get the right post $query->query_vars['post_type'] = self::POST_TYPE; $query->query_vars['p'] = self::get_post_id();

        // override any vars WordPress set based on the original query
        $query->is_single = TRUE;
        $query->is_singular = TRUE;
        $query->is_404 = FALSE;
        $query->is_home = FALSE;
    }
}
}

Might help someone. Again thats for a cracking plugin

Rob

jbrinley commented 11 years ago

Thanks for reporting this, Rob. I'm not able to reproduce the issue, though. Any suggestions on how I might be able to?

robadams22 commented 11 years ago

Hi Jonathan,

I will have a look on monday and send you something over if I get the chance. On holiday at the min but back to the desk next week.

Have a good weekend

Rob Sent from my BlackBerry® smartphone www.blackberry.com

-----Original Message----- From: Jonathan Brinley notifications@github.com Date: Thu, 08 Aug 2013 08:44:08 To: jbrinley/WP-RouterWP-Router@noreply.github.com Reply-To: jbrinley/WP-Router reply@reply.github.com Cc: robadams22rob@itchyrobot.co.uk Subject: Re: [WP-Router] Notice: Undefined property: WP_Query::$post (#5)

Thanks for reporting this, Rob. I'm not able to reproduce the issue, though. Any suggestions on how I might be able to?


Reply to this email directly or view it on GitHub: https://github.com/jbrinley/WP-Router/issues/5#issuecomment-22332709