Forum Replies Created

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter moretothepicture

    (@moretothepicture)

    Hi karidemi,

    I never noticed the slug back end option. Too late now but valid work around.

    In my case it was my fault. I was able to fix it and get the edit button back by str_replacing a section of the url rather than returning a full new url.

    So as a very basic example

    BAD:

    function my_link_filter ($post_link){
    $post_link = home_url() . '/examplepath/';
    return $post_link;
    }

    GOOD:

    function my_link_filter ($post_link){
    $post_link = str_replace('%category%', 'examplepath', $post_link);
    return $post_link;
    }

    I just re-read that sudo code and it would reset the session variable on a new page load.

    if (isset($_GET['s']) && !empty($_GET['s']))
       $_SESSION['search_string'] = $_GET['s'];
    
    if (isset($_SESSION['search_string']))
      echo $_SESSION['search_string'];

    That would only change the session var if the get var was set.

    Again, that’s ^ sudo code, just to push you in the right direction.

    There’s a few options. I would recommend researching using sessions with wordpress and go down that route. You could use javascript as Evan suggests but maybe a simpler version, you could use jquery cookie’s functionality for example.

    Or you could append the links with the GET data if session and JS were not an option.

    Something like…

    $url = 'http://the_original_category_link_or_whatever.com';
    if (isset($_GET['s']) && !empty($_GET['s']))
        $url = add_query_arg('s', $_GET['s'], $url);

    But like I said, I’d go down the $_SESSION route. I’ve successfully used it in numerous WP builds in the past.

    Basically you need to get the session started safely (before any output is sent) then you can just easily add stuff to and retrieve it from the session data.

    $_SESSION['search_string'] = (isset($_GET['s']) && !empty($_GET['s']) ? $_GET['s'] : null;
    
    if (!is_null($_SESSION['search_string']))
       echo $_SESSION['search_string'];

    Yeah the get (and request) var’s are reset on every page request.

    You’d need to save it. You could save it into a $_SESSION variable but a session would need to be started previous to that. (be careful testing this logged in because the admin section would have started it for you, i.e it might not work for visitors)

    The other option would be save it into the database but depending on how you wanted to use the previous search data it might get messy.

    What I really need to know is, what are you going to use the search string for exactly? Is it user specific or site wide?

    I’m presuming your theme passes the request via GET. If it does not, try the $_REQUEST variable instead. $_REQUEST[‘s’] should contain the search query if $_GET[‘s’] doesn’t.

    It’s probably available in the $_GET global variable.

    Try and print_r($_GET) it should contain s=’search string’ – Save or use that as you need.

    Lee.

    Thread Starter moretothepicture

    (@moretothepicture)

    Ignore the second paragraph. “Only moderators can post or move things into this forum.” — my bad.

Viewing 7 replies - 1 through 7 (of 7 total)