I’m currently running Buddypress with Woocommerce activated (Dokan as well.)

From time to time, much more when there’s heavier traffic, there will be random 404 errors on different parts of my website. I heard it has something to do with flush rewrite rules or something.

I’m not too good at these kinds of things, I was wondering if anyone heard of something similar happening. I read that it happens when people also use LearnDash with Buddypress, and I saw a specific fix to be put in functions.php for that, I was wondering if something can be applied to my situation.

Here’s the question that’s similar:

Intermittent 404 errors, rewrite rules, and BBPress

1 Answer 1


To answer your question, if you are not using the LearnDash plugin then you should not add the code that is in the accepted answer of the link you have there.

That code essentially is adding a filter named learndash_flush_rewrite_rules which appears to be specific to that plugin. If you don't have it enabled, it will most likely never run.

I took a look on some tickets and found this BP ticket which may get you started with a different solution.

One person had their issue fixed adding the following to functions.php:

add_action('delete_option_rewrite_rules', function($option){
   global $wp_rewrite;
   $wp_rewrite->use_verbose_page_rules = true;
}, 10);

Definitely test that on a non-prod server before using, not sure why it worked for them, and it was 6 years ago.

Lastly, this is definitely a difficult error to troubleshoot. I'd recommend that you start debugging by logging all your 404 errors and perhaps try to recreate the bug while debugging is turned on. An idea to not disrupt production might be to have a bunch of puppeteer scripts all going to a staging version of your site and log the errors that way.

  • Hello! The code above didn't work, I tried it before But I did find something related to my situation, and I also tried that. I turned on the "Query Monitor" plugin, and found out that on the Request page, it was matching a different Rule, the same rule that it matches on a Buddypress Page, it would match that rule when I get a 404 error on a random non-buddypress page. I tried to implement this code to fix it: buddypress.org/support/topic/… But it gives a critical error. Do you know exactly where to post it?
    – sevenkader
    Commented Jun 12, 2022 at 13:41
  • For me, when it's not working the regexp [^/]+)(?:/([0-9]+))?/?$ is matched. When it is working, (.?.+?) (?:/([0-9]+))?/?$ is matched, I replaced my own match rules with code on the above link and I got ``` if(isset($rewrite['([^/]+)(?:/([0-9]+))?/?$'])) { $temp = $rewrite[^/]+)(?:/([0-9]+))?/?$']; unset($rewrite['([^/]+)(?:/([0-9]+))?/?$']); $rewrite['([^/]+)(?:/([0-9]+))?/?$'] = $temp; } ``` Is this correct? I added it to the class-wp file right after $rewrite = $wp_rewrite->wp_rewrite_rules(); (I don't know what he mans by "in the parse function request"
    – sevenkader
    Commented Jun 12, 2022 at 13:55
  • The most relevant post related to this I found after the above links, is this one below: wordpress.stackexchange.com/questions/216103/… There's a code on that page that may be the answer, do you happen to know how to edit that code so it's related to my situation? I apologize for all the questions
    – sevenkader
    Commented Jun 12, 2022 at 14:22
  • In the wp-class.php file, the parse_request() function starts on line 135. You would paste the code from puckettventures on that buddypress.org post after line 162. So that is what they meant there, did it not work? I wouldn't recommend modifying core WordPress files anyways, but still may help troubleshoot the issue.
    – treckstar
    Commented Jun 20, 2022 at 21:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.