1

I've implemented the accepted answer from this question and works great:

How to create a front end user profile with a friendly permalink

But it does not trigger a 404 if you just enter anything /user/asdasd

I'm thinking it needs to happen at some point in this section of code:

if ( array_key_exists( 'user', $wp_query->query_vars ) ) {
    include (TEMPLATEPATH . '/user-profile.php');
    exit;
}

So check the query_vars then maybe run that through the users database to check?

I'm not really sure how to integrate a 404 redirect if the url is not a user.

Maybe it is something that I put on user-profile.php to check if it returns anything about the user, if not, load the 404 template?

0

I believe the solution here would be as simple as you've generally described it.
Assuming conveniently that $wp_query->query_vars['user'] contains the username and not its ID:

if ( array_key_exists( 'user', $wp_query->query_vars ) ) {
    if ( username_exists( $wp_query->query_vars['user'] ) ) {
        include( TEMPLATEPATH . '/user-profile.php' );
    } else {
        include( TEMPLATEPATH . '/404.php' );
    }
    exit;
}
  • 1
    This worked for me, I added a check to see if user has a certain role before directing to the user-profile template but other than that this worked! Thanks. – Harrison Miracle Oct 11 '16 at 13:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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