Skip Navigation

[Resuelto] Partial Match with Search

This support ticket is created hace 4 años, 5 meses. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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)

Etiquetado: ,

This topic contains 1 respuesta, has 2 mensajes.

Last updated by Luo Yang hace 4 años, 5 meses.

Assisted by: Luo Yang.

Autor
Mensajes
#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.

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