Skip Navigation

[Resolved] Filter multiple custom fields with OR

This support ticket is created 2 years, 4 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

This topic contains 5 replies, has 2 voices.

Last updated by Waqar 2 years, 4 months ago.

Assisted by: Waqar.

Author
Posts
#2240291
Capturar.JPG

Hello, how is everything?

I have a problem that I can't solve and I need your help.

I have a very simple CPT, with some custom fields.

I set up the views correctly and this view has a single field that should search between some custom fields.

The view must search using the OR parameter, however, the selection box does not appear, so I change from AND to OR. same in the attached image.

I use the legacy views plugin and everything is up to date in the latest version, I even created a test environment from scratch, but even with the minimum plugin and the default WP theme, it doesn't work.

I need help urgently.

I'm waiting.

Thanks

#2240379

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Looks like this is the same requirement that was discussed in your other recent ticket.
( ref: https://toolset.com/forums/topic/user-view-with-or-in-the-query-filter/#post-2234021 )

Have you tried the code from my reply to set the custom field filter relation operator to "OR"?

regards,
Waqar

#2240533

it's the same ticket, it's just that I couldn't find the old one and opened a new one.

but man... this is essential, and as I said, even in a pure wp installation with the default theme it doesn't work.

I have more than 10 projects to deliver by the end of the year and they all use views.

doing this work in so many, it's bad for me later.

the problem is that you guys even broke the functionality, and there is no deadline to fix it, then it gets really bad like that.

there is no way to request a maximum priority in this case? this must be affecting many other professionals, as it is an elementary function.

I'm waiting.

#2241283

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

I can understand your concern, but, as I mentioned in the other ticket, this is already highlighted.

I've already added your voice to this matter and will keep you updated on the progress through this ticket.

You can also directly share your feedback about the importance of this feature, using the form on this page:
https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

#2241515

Hello how are you?

this code that you sent me, is it only for posts?

I have several views with users too.

can you send me an example code that works for users?

I'm waiting

thanks

#2242217

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

The code will remain the same for the user views, too.

The only difference would be that the filter "wpv_filter_query" will be replaced with the filter "wpv_filter_user_query":
( ref: https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_user_query )


add_filter( 'wpv_filter_user_query', 'wpv_filter_query_func', 1000 , 3 );
function wpv_filter_query_func( $query_args, $view_settings ) {
    // process if specific view
    if ( ( isset($view_settings['view_id']) && $view_settings['view_id'] == 1234) ) {
        if( !empty($query_args['meta_query']) ) {
            $query_args['meta_query']['relation'] = 'OR';
        }
    }
    return $query_args;
}

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.