chowell18
Member
Posted 2 years ago #
I am displaying the search query on the search results page, but it contains a "+" within the query itself.
Is there an easy way to cleanse/replace that with a space so that the query can actually be utilized as text on the search results page?
Example:
http://www.jockjerseys.com/search/lebron+james/
In the URL, the "+" is fine, but in the search results body where I display the query to the user, I would like it to remove the "+" sign.
Is this possible?
afaik search query is posted in $_GET['s'] array. so in place whare you want to put search query use:
<?php
echo $_GET['s']; ?>
or if it is still with '+', do this:
<?php
echo str_replace('+', ' ', $_GET['s']); ?>
chowell18
Member
Posted 2 years ago #
That's actually not displaying anything now.
Here's what I've been using, although I'm not opposed to only using it for the search count functionality.
<?php /* Search Count */ $allsearch = &new WP_Query("s=$s&showposts=-1"); $key = wp_specialchars($s, 1); $count = $allsearch->post_count; _e(''); _e('<span class="search-terms">'); echo $key; _e('</span>'); _e(' — '); echo $count . ' '; _e('products'); wp_reset_query(); ?>
Still need way to remove the "+" sign though.
chowell18
Member
Posted 2 years ago #
I don't know, maybe my theme has a conflicting function or override of some sort. I tried both versions using the POST and I'm still showing nothing when I use that function.
The official documentation says to use this to show the query:
<?php the_search_query(); ?>
I'm now using this in the breadcrumb menu & using the previous script for the 2nd occurrence and the search count.
Still can't get rid of the "+" though on either.
first off all: why i dont see your answers here but i got them in my mail box?
change:
the_search_query();
into:
function callback($buffer) {
return (str_replace('+', ' ', $buffer));
}
ob_start("callback");
the_search_query();
ob_end_flush();
chowell18
Member
Posted 2 years ago #
I honestly don't know why you can't see them. When I tried to post a reply yesterday it told me the post was closed... Weird stuff going on.
chowell18
Member
Posted 2 years ago #
I can see this here, but all I got in the email was a "."
Some posts may have been temporarily caught in Akismet's spam bin.
@esmi, now i see everything :)
@chowell18, you see dot in email beacause i posted dot and after this i edited post to put (some test) :)
btw. does it work?
chowell18
Member
Posted 2 years ago #
This question is still unresolved btw.... Anyone have a solution?