Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Change results base url
This topic contains 2 replies, has 2 voices, and was last updated by iltdev 10 years, 7 months ago.
- AuthorPosts
- February 12, 2014 at 3:21 pm #974
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.
February 12, 2014 at 3:52 pm #978Hi!
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 :)
February 12, 2014 at 4:17 pm #984Brilliant that worked perfectly 🙂
Is there a way I can target a specific search? Only one of my searches needs the url change. - AuthorPosts
You must be logged in to reply to this topic.