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

WordPress Trac noreply at wordpress.org
Mon Jan 26 22:59:52 UTC 2015

#31140: WordPress 4.0 upgrade caused 404 on single custom post types
 Reporter:  MarjWyatt          |      Owner:
     Type:  defect (bug)       |     Status:  new
 Priority:  normal             |  Milestone:  Awaiting Review
Component:  Posts, Post Types  |    Version:  4.0
 Severity:  normal             |   Keywords:
  Focuses:                     |
 I was alerted to an issue with viewing single custom post types. I
 reverted the site to WordPress v3.9.1 and this was not failing.

 Today, I went through the tedious process of troubleshooting the problem.
 When I upgraded to WordPress 4.0, the code failed.

 I used the following steps to research the problem further:
 1) I enabled the WordPress default theme, the code worked.
 2) Re-enabled my theme and disabled all the plugins to determine whether
 or not there was a plugin conflict. There was not.

 I deduced the problem was in the theme code I'd written.

 I started with functions.php and found this bit of code:
 `// Manually protest wsg-intros because WLM doesn't
 add_action( 'pre_get_posts', 'protect_wsg_intros' );
 function protect_wsg_intros() {
     if ( ( is_post_type_archive ( 'wsg-intros' ) ) && ( !
 is_user_logged_in() ) ) {
         wp_redirect( 'http://localhost/wsg/oops-this-content-is-members-
 only' );
     elseif ( ( is_singular ( 'wsg-intros' ) ) && ( ! is_user_logged_in() )
 ) {
         wp_redirect( 'http://localhost/wsg/oops-this-content-is-members-
 only' );

 When I remarked out the elseif statement, the single custom post type
 worked on my theme with all plugins enabled.

 Great! Problem solved! But the solution leaves me with a question. Why
 would that elseif statement cause a 404 on the single custom post type
 view with the upgrade to WordPress 4.0?  Is this a bug?

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

More information about the wp-trac mailing list