I am using plain simple code to make a search page
$argscontactdirectory = array(
"s" => get_search_query(),
'post_type' => array( 'expertarticle'),
'orderby' => 'title',
'order' => 'ASC',
);
Above is the code I am using, however, when the search query contains the "&" character it simply doesn't work, if the search query is M&M
the URL bar will show ?s=M&M
I tried many things, include urlencode()
, but it doesn't work either.
A live example can be seen here: /?s=hello&p_type=is
Any help is appreciated.
I am using plain simple code to make a search page
$argscontactdirectory = array(
"s" => get_search_query(),
'post_type' => array( 'expertarticle'),
'orderby' => 'title',
'order' => 'ASC',
);
Above is the code I am using, however, when the search query contains the "&" character it simply doesn't work, if the search query is M&M
the URL bar will show ?s=M&M
I tried many things, include urlencode()
, but it doesn't work either.
A live example can be seen here: http://sandbox.indiadairy/?s=hello&p_type=is
Any help is appreciated.
Share Improve this question asked Mar 22, 2019 at 18:34 Deepak KamatDeepak Kamat 1481 silver badge11 bronze badges2 Answers
Reset to default 1get_search_query
escapes the data for outputting to HTML. Can you try the following instead:
$argscontactdirectory = array(
's' => sanitize_text_field( get_search_query( false ) ),
'post_type' => array( 'expertarticle'),
'orderby' => 'title',
'order' => 'ASC',
);
Like this?
$argscontactdirectory = urlencode(
array(
's' => sanitize_text_field( get_search_query( false ) ),
'post_type' => array( 'expertarticle'),
'orderby' => 'title',
'order' => 'ASC',
)
);