Support » Plugin: Simple User Listing » Search Multiple Fields

  • So I’ve added the following code to my functions.php which limits the search bar to ONLY look at last_name. But I’d like to expand it to include first_name and phone_number. How do I let the search bar cover those additional fields?

    function kia_meta_search( $args ){
    
      // this $_GET is the name field of the custom input in search-author.php
        $search = ( isset($_GET['as']) ) ? sanitize_text_field($_GET['as']) : false ;
    
        if ( $search ){
            // if your shortcode has a 'role' parameter defined it will be maintained
            // unless you choose to unset the role parameter by uncommenting the following
            //  unset( $args['role'] );
            $args['meta_key'] = 'last_name';
            $args['meta_value'] = $search;
            $args['meta_compare'] = '=';
    
            // need to unset the original search args
            if( isset( $args['search'] ) ) unset($args['search']);
        }
    
        return $args;
    }
    add_filter('sul_user_query_args', 'kia_meta_search');
Viewing 2 replies - 1 through 2 (of 2 total)
  • By the way “phone_number” is an Advanced Custom Field I’ve added to users… incase that matters.

    Plugin Author helgatheviking

    (@helgatheviking)

    See the “Multiple custom user fields handling” section of the codex for WP_User_Query. So it’s possble to do with WP_User_Query. But while that is the basis for Simple User Listing, SUL can’t quite support that, so you will need to filter the query args and pass a complex meta query. See “How to create very complex user queries | How to query multiple meta keys” section in the FAQ.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Search Multiple Fields’ is closed to new replies.