custom-post-type-permalinks icon indicating copy to clipboard operation
custom-post-type-permalinks copied to clipboard

404 on single post page

Open sijones-uk opened this issue 8 years ago • 8 comments

Since version 2.1.0 I'm getting 404s on all of my single post pages for custom post types. My custom post type (wpbb_job) is defined inside another plugin (WP Broadbean) and has a rewrite slug of 'jobs'. Before v2.1.0 I was able to define the permalink as:

http://<domain>/jobs/%wpbb_job_industry%/%postname%/

where wpbb_job_industry is the taxonomy. This would be transformed into something like this:

http://<domain>/jobs/marketing/digital-marketing/project-manager/

Since v2.1.0 the permalinks are being converted correctly, but clicking on them results in a 404. Previously the correct post would be displayed.

I've narrowed the problem down to Rewrite.php, in particular where you tidied up the code in the add_hook() function and removed the add_action( 'wp_loaded', array( $this, 'add_rewrite_rules' ), 10 ); after v2.0.2. I can't work out why this is causing the 404 though.

sijones-uk avatar Sep 13 '16 19:09 sijones-uk

@sijones-uk have you found any workarounds for this? I tried, but was unsuccessful. For now, are you just using an earlier release?

danielshields avatar Sep 26 '16 18:09 danielshields

@danielshields Unfortunately not, so I can't update the plugin for now, It seems to have been the removal of the line add_action( 'wp_loaded', array( $this, 'add_rewrite_rules' ), 10 ); in Rewrite.php when v2.1.0 was released that broke things. If you want to ensure that the plugin doesn't get accidentally updated you can temporarily change the "Version" in custom-post-type-permalinks.php to 999. However, that's not a good long-term strategy. I haven't found an alternative plugin that does what I need either.

sijones-uk avatar Sep 27 '16 10:09 sijones-uk

I've exactly the same issue - thanks @sijones-uk for the tip to fix in the meantime!

Trenbania avatar Oct 04 '16 15:10 Trenbania

@sijones-uk @danielshields @Trenbania Sorry for late reply.

Replace CPTP_Module_Rewrite use CPTP_set_rewrite_module filter.

Sample code https://gist.github.com/torounit/86c3c140071d29cd1b2fd2900f23c813.

torounit avatar Oct 28 '16 09:10 torounit

Thanks @torounit. Will this fix be folded into the master branch?

sijones-uk avatar Oct 31 '16 09:10 sijones-uk

This seems to be still open with 3.0.0? How can I fix it? My CPT Single is suddenly a 404...

wildfang avatar Feb 06 '17 15:02 wildfang

Version 3.1.1 still with this problem. :'( I'm deactivating the plugin until this is fixed on master, so sad.

caiobleggi avatar Mar 09 '17 21:03 caiobleggi

Review my comment on #79 for my solution with a 404 handler.

enkodellc avatar Oct 19 '18 06:10 enkodellc