I want to change the query of search a custom post type in wordpress admin panel. I use this method:
function change_admin_search( $query ) {
$post_type = 'custom_post_type';
if( ! is_admin() )
return;
if ( $query->query['post_type'] != $post_type )
return;
$search_term = $query->query_vars['s'];
$persian = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
$num = range(0, 9);
$persianNumbersOnly = str_replace( $num,$persian, $search_term);
$englishNumbersOnly = str_replace( $persian, $num, $search_term);
$query->query_vars['s'] = $englishNumbersOnly;
}
add_action( 'pre_get_posts', 'change_admin_search' );
In this query, it search only with $englishNumbersOnly
. I want to search with $englishNumbersOnly
OR $persianNumbersOnly
, and $query->query_vars['s']
have a OR
in query. Actually have a query like this :
post Like "%$englishNumbersOnly%" OR post Like "%$persianNumbersOnly%"
Thanks