Title: Filter query &#8211; is it possible?
Last modified: August 31, 2016

---

# Filter query – is it possible?

 *  Resolved [Steve Cliff](https://wordpress.org/support/users/stevecliff/)
 * (@stevecliff)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/filter-query-is-it-possible/)
 * Currently I’m entering a value into Account Filter of “aoLdapKey” as our LDAP
   server doesn’t use the default of samAccountName.
 * However I currently have to amend the PHP code for the following as there are
   two types of user in LDAP with different prefixes:
 * $filterQuery = “($filter=$username)”;
 * to
 * filterQuery = “(|($filter=AA{$username})($filter=XX{$username}))”;
 * This works ok but I’d love a way of doing this without amending the PHP every
   time a new version is pushed out.
 * Is it possible at all?
 * Thanks!
    Steve.
 * [https://wordpress.org/plugins/wpdirauth/](https://wordpress.org/plugins/wpdirauth/)

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [Paul Gilzow](https://wordpress.org/support/users/gilzow/)
 * (@gilzow)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/filter-query-is-it-possible/#post-7316493)
 * v1.7.14 added filter `wpdirauth_filterquery`.
    v1.7.15 amended filter to pass
   THREE parameters, instead of two.
 * Will pass callback function three parameters: current AD filter and the username
   of the person attempting to authenticate. callback function will need to return
   a valid AD filter that can be used for looking up the user.
 *     ```
       add_filter('wpdirauth_filterquery','mycustomcallback',10,3);
   
       function mycustomcallback($strCurrentFilter,$strFilter,$strUsername)
       {
           return "(|($strFilter=AA{$strUsername})($strFilter=XX{$strUsername}))";
       }
       ```
   
 *  Thread Starter [Steve Cliff](https://wordpress.org/support/users/stevecliff/)
 * (@stevecliff)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/filter-query-is-it-possible/#post-7316510)
 * Thanks for the info – I’m just on a training course at the minute so will see
   if I can get it to work over the weekend. Need to figure out how to use add_filter
   first though – never done that before – lol!
 * Good news it can be done though 🙂
 * Cheers,
    Steve.
 *  Plugin Author [Paul Gilzow](https://wordpress.org/support/users/gilzow/)
 * (@gilzow)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/filter-query-is-it-possible/#post-7316519)
 * just drop the example i posted above into the functions.php file of your theme,
   changing `mycustomcallback` to the function name you want to use. Something like:
 *     ```
       add_filter('wpdirauth_filterquery','steveCliffAdjustWpDirAuthFilter',10,3);
   
       function steveCliffAdjustWpDirAuthFilter($strCurrentFilter,$strFilter,$strUsername)
       {
           return "(|($strFilter=AA{$strUsername})($strFilter=XX{$strUsername}))";
       }
       ```
   
 *  Thread Starter [Steve Cliff](https://wordpress.org/support/users/stevecliff/)
 * (@stevecliff)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/filter-query-is-it-possible/#post-7316524)
 * I broke out of training for lunch and tried this – works absolutely perfect –
   thanks very much !
 *  Plugin Author [Paul Gilzow](https://wordpress.org/support/users/gilzow/)
 * (@gilzow)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/filter-query-is-it-possible/#post-7316526)
 * good to hear. I’m going to go ahead then and mark this one as closed. though 
   let me know if you run into an issue.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Filter query – is it possible?’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/wpdirauth.svg)
 * [wpDirAuth](https://wordpress.org/plugins/wpdirauth/)
 * [Support Threads](https://wordpress.org/support/plugin/wpdirauth/)
 * [Active Topics](https://wordpress.org/support/plugin/wpdirauth/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wpdirauth/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wpdirauth/reviews/)

## Tags

 * [filter](https://wordpress.org/support/topic-tag/filter/)
 * [query](https://wordpress.org/support/topic-tag/query/)

 * 5 replies
 * 2 participants
 * Last reply from: [Paul Gilzow](https://wordpress.org/support/users/gilzow/)
 * Last activity: [10 years, 3 months ago](https://wordpress.org/support/topic/filter-query-is-it-possible/#post-7316526)
 * Status: resolved