Skip Navigation

[Resolved] Custom post type gives “404 Page not found” every day

This thread is resolved. Here is a description of the problem and solution.

Problem: Every day I have to reset my site's permalinks because some posts show 404 errors. After I reset my permalinks the posts show up fine.

Solution: Don't use the same slugs for posts, even in different post types.

This support ticket is created 5 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 7 replies, has 2 voices.

Last updated by timd-5 5 years, 9 months ago.

Assisted by: Christian Cox.

Author
Posts
#1206541

Hi James,

So, the debug log indeed shows some errors: hidden link

Can you help me figure out if one of them is causing the custom post type to disappear?

Kind regards,
Tim de Jong

#1206557

It's hard for me to tell with so many warnings and notices - over 2.3MB of text! All warnings and notices should be fixed in your theme and plugin files to rule them out as the source of the problem. Here are a few worth mentioning:

[26-Feb-2019 20:05:04 UTC] PHP Notice:  Undefined index: deugd in /path/to/site/wp-content/themes/keiindeugden/footer.php on line 85

This is a PHP problem in a theme file.

[26-Feb-2019 20:04:32 UTC] PHP Parse error:  syntax error, unexpected end of file in /path/to/site/wp-content/plugins/redduck/redduck.php on line 75

This is a PHP problem in a plugin file.

[26-Feb-2019 14:30:30 UTC] PHP Warning:  call_user_func_array() expects parameter 1 to be a valid callback, function 'addthis_inline_share_toolbox' not found or invalid function name

This warning points to an issue with implementing a sharing plugin or system, though I'm not quite sure how it's implemented. The error message isn't very specific about it.

[26-Feb-2019 19:45:59 UTC] PHP Notice:  WC_Cart::get_cart_url is <strong>verouderd</strong> sinds versie 2.5. Gebruik in plaats daarvan wc_get_cart_url.

This appears to be a notice about using a WooCommerce function that is deprecated - WC_Cart::get_cart_url. Perhaps the function is called in your theme files or another plugin? That should be replaced as described in the message.

These messages all point to problems in your theme or plugin files which should be resolved, but nothing is obviously causing a problem that would make me believe there is a permalink assignment issue. Is it possible your .htaccess file is being overwritten by some server process or cron? This file configures how your web server handles requests by routing them to the proper place. If your host or developer uses a deployment process to overwrite your existing .htaccess file with another file, that could be part of the problem. One way to test this is to wait until the 404 problem occurs, then download the .htaccess file using FTP before you flush the permalinks. Save that file as a backup, then flush the permalinks. Download the .htaccess file again and compare the two files. This will tell you if something has changed your .htaccess file since you last flushed the permalinks.

#1207420

Hi Christian,

Thank you very much! I saw the debug list and agree it was quite long. I managed to resolve of the issues in there, but I don't think one of them was causing the 404's. (FIY: I have restarted the debugger with a new logfile)

The page hidden link gave me a 404, so I got the "chance" to compare the before and after .htaccess-file again. But as I noticed before, that file doesn't change upon resetting the permalinks. It's always like this:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

So, I haven't found the issue yet. Do you have any thoughts?

Kind regards,
Tim de Jong

#1207816

I'm not sure what could be causing this. It could be a server process run by the host, or some other cron process that turns plugins on and off. It could be a host configuration issue, or something completely unexpected. I can try to install a clone of the site on my own local environment to see if I'm able to reproduce the problem overnight. If so, I will be able to escalate the problem to my 2nd tier team for deeper investigation. If I'm not able to reproduce the problem on my own local environment, and you're unable to reproduce the problem on a development environment, then there is an environmental issue that needs to be investigated by your host company.

If you would like me to run that test on a clone of your site, please provide login credentials in the private reply fields here. I will install the Duplicator plugin to create that site clone and set up a test.

#1209731

Hi Christian,

One more thing: I have added a piece of code to functions.php which is supposed to resave the permalinks every hour. I hope that that will at least resolve the issue every time it occurs. So it's not a real solution, but just some tape to keep the site going for now.

You might want to remove that code when you're testing. It's at the bottom of functions.php, lines 573 to 587.

Kind regards,
Tim de Jong

#1209734

Okay I installed a clone of your site locally, then I deactivated all plugins except Types, Views, WooCommerce Views, and WooCommerce. Then I checked these posts and they seem to be appearing as expected:
hidden link
hidden link

I also edited this post and made a minor text update:
hidden link

Then I added two new posts:
hidden link
hidden link

Now I will wait overnight to see if I get 404s tomorrow. I'll give you an update tomorrow evening.

#1210282

No 404s on my site today, so I'm not really sure how to replicate the problem. You're not supposed to use the same slug for more than one post, regardless of whether or not it's in a different post type. If you do a google search for "wordpress same slug different post types", you'll see some discussion about this. It apparently becomes a major issue when the permalink structure is %postname%, like on your site. I don't know a good way around this, since WordPress recommends all posts have a unique slug. A regular cron process might be your best option.
https://core.trac.wordpress.org/ticket/18962

#1221571

My issue is resolved now. Thank you!