This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

{USER_LOGIN} parameter

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #22281
    sabbellasabbella
    Participant

    Hello,

    I need a custom URL scheme in “General Options -> User search” , with {USER_LOGIN} at the end of the url.

    The problem is that I need to get the users without spaces, without @, with – instead of . and lowercase.

    I have this code:

    foreach ( $user ) {
    $usuario = $user->user_login;
    $usuario = str_replace(“.”,”-“, $usuario);
    $usuario = str_replace(” “,”-“, $usuario);
    $usuario = str_replace(” “,”-“, $usuario);
    $usuario = str_replace(“@”,””, $usuario);
    $usuario = strtolower($usuario);
    echo esc_html( $usuario );

    How can include it to the {USER_LOGIN} parameter?

    Thank you,

    #22285
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi,

    Well, the only way to do that is by completely changing the result URL, as that parameter is replaced without any filtering. I have made a custom code to start you off with. Try adding this custom code to the functions.php in your theme/child theme directory. Before editing, please make sure to have a full site back-up just in case! I did not test this code, so please be careful. Change the $r->link line according to your needs:

    add_filter( 'asp_results', 'asp_custom_user_url', 10, 1 );
    function asp_custom_user_url( $results ) {
      foreach ($results as $k => &$r ) {
        if ( $r->content_type == 'user' ) {
          $user = get_user_by('ID', $r->id);
          
          // Your custom code
          $usuario = $user->user_login;
          $usuario = str_replace(".","-", $usuario);
          $usuario = str_replace(" ","-", $usuario);
          $usuario = str_replace(" ","-", $usuario);
          $usuario = str_replace("@","", $usuario);
          $usuario = strtolower($usuario);
          //echo esc_html( $usuario );
          
          $r->link = home_url("/") . $usuario; // Build your custom URL structure here
        }
      }
      return $results;
    }
    #22289
    sabbellasabbella
    Participant

    Thank you Ernest, it works super-fine 🙂

    I have other issue, I only get a maximum of 20 search results, always, although it should be more results displayed. Is there any option where this is set?

    Thank you,

    #22290
    sabbellasabbella
    Participant

    You cannot access this content.

    #22291
    Ernest MarcinkoErnest Marcinko
    Keymaster

    You cannot access this content.

    #22293
    sabbellasabbella
    Participant

    Thank you 🙂

    #22297
    Ernest MarcinkoErnest Marcinko
    Keymaster

    You cannot access this content.

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.