Support

Account

Home Forums General Issues Taxonomy Matching Starting with first letter typed (not third)

Solved

Taxonomy Matching Starting with first letter typed (not third)

  • I searched pretty deep in the forum and didn’t see this question, which was a bit surprising. I also realize it isn’t ACF specific (I think).

    For taxonomy select, you have to type in three letters for the top results to show words that start with those letters. Otherwise…

    …if you type in “ca”, the results will show words that don’t start with “ca” until you hit that third letter.

    I figure there is a jQuery or maybe php solution. Asking on here to save trying to customize a more generalized solution I find online. thanks

    Note: this is for a front end form, if that makes a difference., but none of them immediately seem similar to my issue.

  • The search is actually searching for any occurrence of the characters typed. entering “c” would get anything containing a “c”, same with “ca”. It only happens to be that once you enter 3 letters you narrow the results enough to get words starting with the search value. It’s the way that searching works in WP.

  • Ah-thanks. Rhetorical question, but worth asking. Are you aware of any workarounds?

    I have ~10,000 tags and it will be potentially be confusing to my users.

    I was thinking there had to be some WP Query $arg for this.

  • ACF populates the "search" argument for get_terms() https://developer.wordpress.org/reference/functions/get_terms/ with the entered value. also see https://developer.wordpress.org/reference/classes/wp_term_query/__construct/

    WP automatically changes this to "%{$search}%"

    In order to change it to `”{$search}%”, which is what you’d need to do to only get results that start with what’s entered, you’d need to alter the SQL query. I’m sure this is possible using some filter in WP, but I don’t know what that filter is or how you’d use it.

    Doing a quick look this would probably be done using this hook https://developer.wordpress.org/reference/hooks/terms_clauses/, but there isn’t much in the way of documentation that I found. This seems to be headed in the direction you want https://wordpress.stackexchange.com/questions/123298/term-begins-with-a-letter

  • Thanks so much. Super helpful. I spent a couple hours digging based on your info and unfortunately have been unable to get it to work. I will update this post if I’m able to figure it out.

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Taxonomy Matching Starting with first letter typed (not third)’ is closed to new replies.