Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › RPS Plugin Shortcode Appear on Results Page
- This topic has 7 replies, 2 voices, and was last updated 9 years, 3 months ago by
Ernest Marcinko.
-
AuthorPosts
-
February 27, 2017 at 9:10 pm #12128
sschoch
ParticipantHi, Ernest:
Some of the pages in our system contain only a shortcode (via the RPS Include plugin) to include content from another page. When Ajax Search Pro returns these pages in a search, it shows the shortcode as the excerpt (see attached). I have tried enabling the Advanced Options -> What to do with shortcodes in results content? > Execute them option, but it doesn’t change anything. Clicking the page title goes to the page, which activates the shortcode and displays the page content, so no problem there.
Is there a way to display an excerpt from the included text? If not, is there a way to hide the excerpt when it contains only a shortcode?
Thank you, Stephanie Schoch
February 28, 2017 at 11:07 am #12136Ernest Marcinko
KeymasterHi Stephanie,
I’m afraid the issue is not related to ajax search pro in this case. The plugin only passes on the post objects to the results handler, the displaying is done via the theme, I’m guessing via the the_excerpt() call, at least that it what most themes usually do.
I believe it is possible however to execute shortcodes in excerpts: https://goo.gl/3Aus3q
You might need to ask the theme developer on how exactly change the contents there 🙂
February 28, 2017 at 4:58 pm #12143sschoch
ParticipantHi, Ernest:
The problem I described above wasn’t accurate. I fixed it by turning on the option to have Ajax Pro replace the theme’s search. So the search results look fine now.
BUT, I do have another problem. You might remember that you gave me the code pasted in below to fix the issue where links to our online help system in the search results were going to post names, but the pages on the online help system use page IDs. This works great for links that appear in the live search results, but not when I click links on the Search Results page. Those still try to go to a post name.
Is there a modification you can make to the code below to make it work for links on the Search Results page also or is there another solution?
[code]
add_filter(‘asp_results’, ‘asp_try_fixing_permalinks’, 10, 1);
add_filter(‘asp_regular_search_result’, ‘asp_try_fixing_permalinks’, 10, 1);function asp_try_fixing_permalinks( $results ) {
$url = ‘Help site path’; // Change this to the help site path, like http://site.com
foreach ($results as $k => &$r) {
if ( isset($r->asp_guid) ) {
if ( strpos($r->asp_guid, $url) !== false ) {
$r->asp_guid = $url . ‘?page_id=’ . $r->ID;
}
} else {
if ( strpos($r->link, $url) !== false ) {
$r->link = $url . ‘?page_id=’ . $r->id;
}
}
}return $results;
}
[/code]March 1, 2017 at 11:04 am #12147Ernest Marcinko
KeymasterHi,
In that case there might have been something else overriding the results (or perhaps modifying them in some way), I’m guessing by turning on the override option on the search fixes that as it passes the objects correctly. Anyways, it is fixed and that’s great.
Changing the links on the results page very much depends on how the theme outputs them, and unfortunately there is a good chance that they might not be changeable with the standard known methods, I’m not sure to be honest.
I’ve taken a sample solution from the wordpress documentation, which should work in most cases for changing the permalinks on the results page:Again, this very much depends on the theme itself, but it’s worth a try.
March 1, 2017 at 4:18 pm #12149sschoch
ParticipantHi, Ernest:
I added the code to the theme’s functions.php file. All of the links to the help site go to a page with a page ID of -10. Any ideas?
https://stage-help.netbase.com/cb/help/ic2/?page_id=-10
Thanks, Steph
March 2, 2017 at 10:03 am #12154Ernest Marcinko
KeymasterHi Steph,
Interesting. How about this modification:
March 2, 2017 at 4:33 pm #12160sschoch
ParticipantHi, Ernest:
That worked, thank you.
Now, one more thing. When I include courses and lessons in the search and click the links in the results (either the drop-down list under the search box or the results page), I get a “Page Not Found” error. These all reside on the same site with the Ajax search box. I’ve included a screenshot of the post types added on the General Options -> Sources tab. Am I forgetting to do something?
March 3, 2017 at 12:08 pm #12170Ernest Marcinko
KeymasterHi,
Assuming that both the drop-down and the results page results URLs are overwritten, I’m guessing that the $url variable is most likely set incorrectly, or maybe the page_id=.. solution doesn’t work for them. Maybe the ID solution should apply to ‘page’ post types only? In that case try changing both of the codes to this:
(don’t forget to change the $url variables in both case)
-
AuthorPosts
- You must be logged in to reply to this topic.