Created
December 28, 2020 21:09
-
-
Save stefanRepac/ccd14c602def2c64e6a8ea1ca31326ba to your computer and use it in GitHub Desktop.
Snippet for StackOverflow - https://stackoverflow.com/questions/65479448/search-form-redirect-to-home-page-after-you-search-with-cyrillic-letters-only/65481297#65481297
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
const CYR = array('а','б','в','г','д','ђ','е','ж','з','и','ј','к','л','љ','м','н','њ','о','п','р','с','т','ћ','у','ф','х','ц','ч','џ','ш','А','Б','В','Г','Д','Ђ','Е','Ж','З','И','Ј','К','Л','Љ','М','Н','Њ','О','П','Р','С','Т','Ћ','У','Ф','Х','Ц','Ч','Џ','Ш'); | |
const LAT = array('a','b','v','g','d','đ','e','ž','z','i','j','k','l','lj','m','n','nj','o','p','r','s','t','ć','u','f','h','c','č','dž','š','A','B','V','G','D','Đ','E','Ž','Z','I','J','K','L','LJ','M','N','NJ','O','P','R','S','T','Ć','U','F','H','C','Č','DŽ','Š'); | |
function cyr_to_latin( $string ) { | |
return str_replace(CYR, LAT, $string); | |
} | |
function latin_to_cyr( $string ) { | |
return str_replace(LAT, CYR, $string); | |
} | |
function searchfilter($query) { | |
$search_term = get_search_query(); | |
$latin_conversion = cyr_to_latin($search_term); | |
$urldecode = urldecode($latin_sanitize); | |
if ($query->is_search && !is_admin() ) { | |
$query->set('post_type',array('post','page')); | |
$query->set('s',$urldecode); | |
} | |
return $query; | |
} | |
add_filter('pre_get_posts','searchfilter'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment