Skip Navigation

[Resolved] Partial Match with Search

This support ticket is created 5 years, 1 month 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/Hong_Kong (GMT+08:00)

This topic contains 1 reply, has 2 voices.

Last updated by Luo Yang 5 years, 1 month ago.

Assisted by: Luo Yang.

Author
Posts
#1378481

I have a field that is "single line" but right now only contains numbers (it may be alphanumeric in the future). I want a search that works with partial matches. I've selected the "like" operator, but that isn't working.

The problem seems to be that the value for this field is 7 or 8 digits long. But the string I'm entering into the search is longer. It still contains those 7 or 8, but has 5 additional at the front.
For example:

ID Number Value - 1234567
My Search Query - 045321234567

Results: None

The "like" operator doesn't recognize that query as containing the partial value.

Is there a functions or javascript solution to this that you know offhand? Something that chopped off the first few digits before submitting (or even an interim form) would be great.
The reason I have to do it this way is because we're scanning an ID card and there is extra data prepended to everyone's ID number. In the system it'll be 7 digits, but on the card it'll be 12 (those first 5 not mattering).

#1378567

Hello,

There isn't such kind of features within Toolset plugins, it needs custom codes, here are my suggestion:
1) When user submit the custom search form, you can use Views filter hook "wpv_filter_query" to trigger a custom PHP function:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

2) In this PHP function, apply your "partial matches":
https://developer.wordpress.org/reference/classes/wp_query/#custom-field-post-meta-parameters

For your reference.