{USER_LOGIN} parameter

This topic contains 6 replies, has 2 voices, and was last updated by

 
Keymaster
2 years, 9 months ago.

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

    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

    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;
    }
    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #22289

    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

    Participant
    You cannot access this content.
    #22291
    You cannot access this content. Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #22293

    Participant

    Thank you 🙂

    #22297
    You cannot access this content. Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.