Skip Navigation

[Resolved] Search trough two fields with one filter

This support ticket is created 4 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 7 replies, has 2 voices.

Last updated by zeljko-turkaljS 4 years, 10 months ago.

Assisted by: Minesh.

Author
Posts
#1450235

Is it possible to search trough two fields, for example, text search trough title and description. Title and description are two fields in custom post type.

#1450259

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Toolset views offer the integration with the "Relevanssi" plugin using which you can add the custom field in search.

I suggest please go through the steps given with the following Doc and try to resolve your issue;
=> https://toolset.com/documentation/user-guides/views/searching-texts-custom-fields-views-relevanssi/#including-custom-fields-in-the-search

Please feel free to get in touch with us if you require further assistance.

#1450481

Hi Minesh, thanks for your quick reply, but this is not what I want, I already have form, just need to map two custom fields in one filter.

Please check this form and advise how to do this: hidden link

The field in search form (filter in search form) is Keyword search

Thanks

#1450485

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Ok - do you mean that if I try to search for the keyword "chess" it should search in the custom field description field as well as post title?
- additionally, what post it should return, post having "chess" in both post title and description field OR post having "chess" in any of the field post title or description field

Can you please clarify this and send me admin access details so I can check further.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1450957

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please check now:

I've added the following code to "Custom Code" section offered by Toolset;
=> hidden link

add_filter('wpv_filter_query', 'func_search_in_title_or_custom_field', 10, 3);
function func_search_in_title_or_custom_field($view_args, $setting,$view_id) {
    if($view_id == 731466) {
         
        if(isset($_GET['wpv-wpcf-description']) and !empty($_GET['wpv-wpcf-description'])){
          
             $view_args['s'] = $_GET['wpv-wpcf-description']; // passing keyword to search
          
             $target_field = 'wpcf-description'; // target keword field 
          
               foreach ($view_args['meta_query'] as $key => $value) {
                if(is_array($value)) {
                    if ($value['key'] == $target_field) {
                      	$x = $value;
                        unset($view_args['meta_query'][$key]);
                    }
                }
            }
            $view_args['meta_query'] = array('relation'=>'OR',
                                             $view_args['meta_query'],
              							array( 
                                             $x));
       }
        }
return $view_args;
}

I tried to search with the keyword: repair
=> hidden link

Can you please confirm it works as expected.

#1451077

Awesome Minesh, thanks, I believe this is it. Thanks for your great support

#1451093

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Great - glad to know that solution I shared help you to resolve your issue.

Please feel free to mark resolve the ticket.

#1451209

My issue is resolved now. Thank you!