bbPress 2.x – Cure 404 header in Users Profiles

When bbPress is parsing a user query it sets the author_name query var.

    // Set author_name as current user's nicename to get correct posts
    $posts_query->set( 'author_name', $user->user_nicename );

This could be useful if you want to show user’s blog posts as the query_var above tells WordPress to do exactly that. If WordPress fails to return posts $wp->handle_404(); comes along and sets the 404 despite the fact bbPress is trying to prevent it earlier on parse_query action.

I rolled my own fix.

function bbp_fix_users_404_headers() {
    if ( ! function_exists( 'bbpress' ) ) return;       
    $bbp = bbpress();

    if ( !empty( $bbp->displayed_user ) && is_404() ) {
        global $wp_query;
        $wp_query->is_404 = false;
        status_header( 200 );
add_action( 'wp', 'bbp_fix_users_404_headers' );

Personally i put these in MU file as i often need to set hooks before plugins’ run-time. For this one theme’s functions.php is OK too.

10 Responses to “bbPress 2.x – Cure 404 header in Users Profiles”

  1. Stoyan Kyosev

    Thanks mate!

    This error has been haunting our support forums since weeks and I wasn’t able to find a fix.

    Strange it isn’t reported on the bbpress bugtracker yet. I’ll do it and I’ll refer to your post.

    Owe you a beer! Cheers!

  2. dienstbote

    This was the solution! Thanks mate! It works like a charm! Greetings from germany :D

  3. Rob

    Hi. I’ve been looking for a solution for this problem and this could be it but I’m no php expert, could you tell me how to implement this, where am I to put this code?


    • zlatev

      Hi @Rob, If you’re already using the latest version of bbPress this shouldn’t be an issue as this bug is fixed as of version 2.2. If not go to your theme’s functions.php and drop these lines.

  4. hassa

    my user_nicename = user_login … so it does not work … then I updated user_nicename to something else then it worked. Why would that happen?

  5. Tom Schultz

    Your code worked for me on functions.php, thanks!!

  6. mac

    It worked ok form me also. Thanks very much¡¡

    In my case, the error you solved happened when you allow anonymous users to make responses and then you click on the user profile assigned automatically.

  7. Dirk

    Works! :)
    Thanks you very much!

  8. John

    I too, was just bit by this. I’d prefer not to need this work-a-round, but after adding this, profile pages are no longer 404. Thanks!


Leave a Reply to Stoyan Kyosev Cancel reply