Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Replace result-urls with something else
- This topic has 3 replies, 2 voices, and was last updated 5 years, 10 months ago by
Ernest Marcinko.
-
AuthorPosts
-
July 31, 2020 at 6:52 pm #28776
Julius89
ParticipantHello!
I would like to replace only particular result-urls (not all urls) with other urls on the live-results.
So for examplewebsiteurl1.com should be replaced with google.com
and
websiteurl2.com with wikipedia.com
and
websiteurl3.com should not be changed.I found this documentation on the ajax search pro-website: https://knowledgebase.ajaxsearchpro.com/miscellaneous/other/how-to-change-the-results-url-to-something-else
Could you point out which code-snippets I have to modify to make this happen?
Thank you very much
Julius
August 1, 2020 at 9:16 am #28777Ernest Marcinko
KeymasterHi Julius,
You are looking for this code snippet:
add_filter( 'asp_results', 'asp_custom_link_results', 10, 1 ); function asp_custom_link_results( $results ) { // Parse through each result item foreach ($results as $k=>$v) { /** * In this context the * $results[$k]->link * variable holds the result link. Make modifications to that variable. */ $results[$k]->link = 'https://google.com'; } return $results; }I would recommend something like this:
add_filter( 'asp_results', 'asp_custom_link_results', 10, 1 ); function asp_custom_link_results( $results ) { // Array of original -> replacement links $replace = array( 'websiteurl1.com' => 'google.com', 'websiteurl2.com' => 'wikipedia.com' ); // Parse through each result item foreach ($results as $k=>&$r) { /** * In this context the * $results[$k]->link * variable holds the result link. Make modifications to that variable. */ $r->link = str_replace(array_keys($replace), array_values($replace), $r->link); } return $results; }Just enter the values to the $replace variable. On each line, the left side is the value to replace, with the value on the right side.
August 4, 2020 at 8:03 pm #28809Julius89
ParticipantHi!
The result-linke isn’t replaced properly but instead “google.com” is added to the existing link.
But this is no problem for me. I have chosen a different solution with ajax search pro for my project, that doesn’t rely on this customization. So I don’t want to replace the result-link anymore.
Thanks for your efforts! I like Ajax Search Pro very much.
Julius
August 5, 2020 at 8:24 am #28812Ernest Marcinko
KeymasterYou cannot access this content.
-
AuthorPosts
- You must be logged in to reply to this topic.