Displaying Related posts on 404 page with shortcode
-
Hi Aldolat
I was trying to find a way to display posts, related to the url of 404 page.
So if you access /journey, which doesn’t exist and returns a 404 page, ideally it’s supposed to display posts suggestions based on the search=”journey”.I’ve found that one can use shortcodes and search option, but I don’t know if it’s possible to pass the URL value as the search parameter.
I’ve managed to get it working somehow:
<?php $test123 = $_SERVER['REQUEST_URI']; $url = trim($test123, '/'); echo $url; echo do_shortcode("[pissc search=\"$url\" orderby=title number=5]"); ?>
But the results are a bit different from the normal search query –
- e.g https://pdidner.staging.wpengine.com/takeaway shows only 2 posts with a word ‘takeaway’ in title
- while a search https://pdidner.staging.wpengine.com/?s=takeaway returns at least 5 posts with ‘takeaway’ in title.
Tried changing the orderby to title/name with no difference. Debug is enabled.
Am I missing something? Any help is greatly appreciated.
Regards,
Alex
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Displaying Related posts on 404 page with shortcode’ is closed to new replies.