Change results base url

This topic contains 2 replies, has 2 voices, and was last updated by iltdev iltdev 8 years, 3 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #974
    iltdev
    iltdev
    Participant

    Loving v2! It’s fantastic!

    Just one thing I need to do. I need to change the base url that the search results go to. The slug would remain the same e.g. instead of /events/post-slug it would be /course/post-slug.

    I’ve tried using livequery to catch the click so I would change the url myself:

    
    $('item h3 a') 
        .livequery(function(){ 
            $(this) 
                .click(function() { 
                    alert('clicked');
                }); 
        });
    

    But this didn’t work.

    #978
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    Thank you! I would rather recommend using PHP to achieve such thing insted of javascript. The good thing with v2.0 is that I have implemented a bunch of filters and actions, that we can use to make our lives easier 🙂

    However there is no filter for changing the url, there is still a way around it. The filter called “asp_results” passes all the results as an array of objects to a desired function. This means, that we can scrape the url out of it and change it as we like:

      add_filter('asp_results', 'my_changeBaseUrl',10,1);
      
      function my_changeBaseUrl($results) {
          foreach ($results as $k=>$result) {
            $results[$k]->link = str_replace("replace this", "with this", $result->link);
          }
          return $results;
      }

    You can put this code to you templates functions.php file, or into the bottom of the plugins/ajax-search-pro/search.php file. If you replace the “replace this” and the “whith this” string in this code with the desired string, it should work 🙂

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #984
    iltdev
    iltdev
    Participant

    Brilliant that worked perfectly 🙂
    Is there a way I can target a specific search? Only one of my searches needs the url change.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.