WordPress.org

Ready to get started?Download WordPress

Forums

Cleanse search query for display on Search Results page (12 posts)

  1. chowell18
    Member
    Posted 3 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?

  2. kkarpieszuk
    Member
    Posted 3 years ago #

    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']); ?>
  3. chowell18
    Member
    Posted 3 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(' &mdash; '); echo $count . ' '; _e('products'); wp_reset_query(); ?>

    Still need way to remove the "+" sign though.

  4. kkarpieszuk
    Member
    Posted 3 years ago #

    change GET to POST

  5. chowell18
    Member
    Posted 3 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.

  6. kkarpieszuk
    Member
    Posted 3 years ago #

    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();

  7. chowell18
    Member
    Posted 3 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.

  8. kkarpieszuk
    Member
    Posted 3 years ago #

    (some test)

  9. chowell18
    Member
    Posted 3 years ago #

    I can see this here, but all I got in the email was a "."

  10. esmi
    Forum Moderator
    Posted 3 years ago #

    Some posts may have been temporarily caught in Akismet's spam bin.

  11. kkarpieszuk
    Member
    Posted 3 years ago #

    @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?

  12. chowell18
    Member
    Posted 3 years ago #

    This question is still unresolved btw.... Anyone have a solution?

Topic Closed

This topic has been closed to new replies.

About this Topic