[wp-trac] [WordPress Trac] #31140: WordPress 4.0 upgrade caused 404 on single custom post types

WordPress Trac noreply at wordpress.org
Tue Feb 3 06:41:02 UTC 2015


#31140: WordPress 4.0 upgrade caused 404 on single custom post types
-------------------------------+-------------------------
 Reporter:  MarjWyatt          |       Owner:
     Type:  defect (bug)       |      Status:  closed
 Priority:  normal             |   Milestone:
Component:  Posts, Post Types  |     Version:  4.0
 Severity:  normal             |  Resolution:  worksforme
 Keywords:                     |     Focuses:
-------------------------------+-------------------------
Changes (by dd32):

 * status:  new => closed
 * resolution:   => worksforme
 * milestone:  Awaiting Review =>


Comment:

 Calling template tags, such as `is_singular()` before the posts have been
 queried is rather unreliable - unreliable in that WordPress doesn't yet
 know what the current post/page is on `pre_get_posts` so it can't reliably
 tell you what the status of the request is. Running that code on something
 such as `template_redirect` should solve that problem though.

 That being said, I can't reproduce this in trunk, the is_singular() does
 nothing since the post isn't loaded, and doesn't affect the query, the
 single post is still loaded (logged in, or not).

 Additionally, you should check
 [http://codex.wordpress.org/Function_Reference/is_main_query
 is_main_query()] in pre_get_posts callbacks to prevent also running on
 other queries (such as theme sidebars listing posts, etc). You should also
 enable [http://codex.wordpress.org/WP_DEBUG WP_DEBUG] as that'll have
 indicated a PHP Notice due to calling is_singular too early.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/31140#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list