• Resolved jjnimes

    (@jjnimes)


    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/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter jjnimes

    (@jjnimes)

    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

    (@helgatheviking)

    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, which can be achieved by filtering 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

    (@jjnimes)

    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

    (@jjnimes)

    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

    (@jjnimes)

    Or is there a value for wildcard?

    Plugin Author HelgaTheViking

    (@helgatheviking)

    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

    (@jjnimes)

    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.