Title: Query problem
Last modified: August 31, 2016

---

# Query problem

 *  Resolved [jjnimes](https://wordpress.org/support/users/jjnimes/)
 * (@jjnimes)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/query-problem-3/)
 * I successfully modified my filtering inputs but the result of query is not correct.
   There are extra results or no results even changing the relation to my custom
   filters ‘OR’ or ‘AND’. Also it seems that the default relation of default filter
   is ‘OR’. Is there a way to modify the whole query that if there is no value on
   the field will not be included in the query?
 * Example
    `?as=&gender=Male&civil_status=`
 * Since there is no value for civil_status it should be
 * `?as=&gender=Male`
 * so it will not be included in the query then my relation will be ‘AND’ because
   if I use ‘OR’ there are extra results
 * [https://wordpress.org/plugins/simple-user-listing/](https://wordpress.org/plugins/simple-user-listing/)

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

 *  Thread Starter [jjnimes](https://wordpress.org/support/users/jjnimes/)
 * (@jjnimes)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/query-problem-3/#post-7009593)
 * The name field is your default field in this plugin and it seems that it has 
   an OR relation to my custom fields where the relation that I’m changing is only
   on my custom fields.
 * Example
    // relation is OR Name = ” Gender = ‘Male’ Status = ” Result is mixed
 * // relation is AND
    Name = ” Gender = ‘Male’ Status = ” Result is OK
 * // relation is OR
    Name = ‘Mary’ Gender = ‘Female’ Status = ” Result is OK
 * // relation is AND
    Name = ‘Mary’ Gender = ‘Female’ Status = ” No result
 *  Plugin Author [HelgaTheViking](https://wordpress.org/support/users/helgatheviking/)
 * (@helgatheviking)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/query-problem-3/#post-7009686)
 * I’m sorry, but searching by multiple meta fields is not supported “out of the
   box”. This type of complex user query probably needs a custom [`WP_User_Query`](https://codex.wordpress.org/Class_Reference/WP_User_Query),
   which can be achieved by filtering [`pre_get_users`](https://developer.wordpress.org/reference/hooks/pre_get_users/)
   but is not covered under support.
 * I will note that SUL passes a `query_id` parameter equal to `simple_user_listing`
   by default (but can accept an even more custom ID via shortcode parameter). You
   can use this to apply your filter modifications strictly to your custom query
   and only your custom query.
 *     ```
       function kia_custom_query( $query ) {
   
         if ( isset( $query->query_vars['query_id'] ) && $query->query_vars['query_id'] == 'simple_user_listing' ) {
            // do something to your user query
         }
   
       }
       add_action( 'pre_user_query', 'kia_custom_query' );
       ```
   
 *  Thread Starter [jjnimes](https://wordpress.org/support/users/jjnimes/)
 * (@jjnimes)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/query-problem-3/#post-7009710)
 * Sorry but I don’t understand the function of your given code. Could it do what
   I need? I need to not include in the query the fields that does not have value
   like
 * Name = ‘Mary’ Gender = ‘Female’ Status = ”
 * ?as=Mary&gender=Female&civil_status=
 * Since status has no value, it should be
 * ?as=Mary&gender=Female
 *  Thread Starter [jjnimes](https://wordpress.org/support/users/jjnimes/)
 * (@jjnimes)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/query-problem-3/#post-7009712)
 * Anyway by the way I think I found an alternative. I just removed the default 
   field and create my own for names. Is there a way that my field could find the
   string that contains it?
 *  Thread Starter [jjnimes](https://wordpress.org/support/users/jjnimes/)
 * (@jjnimes)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/query-problem-3/#post-7009721)
 * Or is there a value for wildcard?
 *  Plugin Author [HelgaTheViking](https://wordpress.org/support/users/helgatheviking/)
 * (@helgatheviking)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/query-problem-3/#post-7009728)
 * The code does nothing, it is just an example of how you would need to filter `
   pre_get_users`…. which is what you need to do, though I don’t know what the exact
   parameters you need. To reiterate what I said in the other thread, if your meta
   search box has no value, do not add it to the query at all. That works better
   than trying to add it with a blank value or with a wild card. Good luck.
 *  Thread Starter [jjnimes](https://wordpress.org/support/users/jjnimes/)
 * (@jjnimes)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/query-problem-3/#post-7009745)
 * Thank you for the answer but I created another for that topic though.

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

The topic ‘Query problem’ is closed to new replies.

 * ![](https://ps.w.org/simple-user-listing/assets/icon-256x256.png?rev=3061308)
 * [Simple User Listing](https://wordpress.org/plugins/simple-user-listing/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/simple-user-listing/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/simple-user-listing/)
 * [Active Topics](https://wordpress.org/support/plugin/simple-user-listing/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/simple-user-listing/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/simple-user-listing/reviews/)

## Tags

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

 * 7 replies
 * 2 participants
 * Last reply from: [jjnimes](https://wordpress.org/support/users/jjnimes/)
 * Last activity: [10 years, 4 months ago](https://wordpress.org/support/topic/query-problem-3/#post-7009745)
 * Status: resolved