Skip Navigation

[Resolved] Search filters doesn't work unless I use Relevanssi

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 3 replies, has 3 voices.

Last updated by Nigel 10 months, 3 weeks ago.

Assisted by: Minesh.

Author
Posts
#2679712
Screenshot 2024-01-23 at 22.17.21.png

Tell us what you are trying to do?
Hi,

I have a search page where I do the search by using various filters. There's also one free text search field there which will use relevanssi for searching.

This used to work without an issue but I realised today that some of the filters don't work at all. If I use the free text search field and rely on relevanssi, then all search filters work without an issue.

The problem occurs when I use the custom fields to search. Searching based on taxonomies work without an issue so far.

I attached the screenshot of the filter definition if that makes things easier

Is this a known issue?

Is there any documentation that you are following?

Is there a similar example that we can see?
hidden link
Try filtering by age, for example select 4 from the dropdown. What it is supposed to do is to find all event where min age <= 4 <= max age. You'll see in the results that records that are outside of the age range will still exists on the search results.

Try adding some text into the "What are you looking for?" text field, you'll see that it is working as it should.

What is the link to your site?
hidden link

#2679719

I was able to apply a workaround to "fix it" on live website by forcing a default value for the free text search, so visitors don't experience a big issue, but you can still see the problem on the staging website that I linked you in previous post

#2679802

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

That is really strange.

I will have to check what is the query generated by the view when you select age as 4.

Can you please send me admin access details for your staging site and let me review whats going wrong with your setup.

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

#2679807

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

I'm not sure what the issue is here. I set up a comparable test on a clean test site just now, and everything works as expected. The custom field filters work, irrespective of whether any text is entered in the text search box or not.

I visited your search page, but I'm not sure what I'm looking at.

The filter for age lets you choose a single value (e.g. 10), but the list of posts shown output age as a range (e.g. 4 - 13), so they don't appear comparable.

If you would like us to investigate the issue on your site can we get credentials from you?

Let me mark your next reply as private so that we can get log-in credentials from you—you may want to create a temporary admin user for us to use that you can later delete. And be sure to have a current backup of your site.

#2679933

Hi all,

Thank you for the support on this one. It was really strange I agree as it was working without problems before. I realised that's because of a code we introduced some time ago and we broke the search without realising.

Basically, I had a piece of code where I was trying to sort the order of the results, but I ended up overriding the whole search criteria. This was running in a "wpv_filter_query" hook, which was why the search was ok when I used relevanssi.

$query_args['meta_query'] = array(
'relation' => 'AND',
'featured_orderby' => array(
'key' => 'wpcf-featured',
'type'=>'numeric',
'compare' => 'EXISTS',
),
'event_status_orderby' => array(
'key' => 'wpcf-event-status',
'compare' => 'EXISTS',
),
);

$query_args['orderby'] = array(
'featured_orderby' => 'DESC',
'event_status_orderby' => 'ASC',
'post_date' => 'DESC'

);

I was able to fix the code here and now we are good. Thanks again.