Forums › Forums › Search & Filter Pro › Deploying search results to a CPT single page
- This topic has 4 replies, 2 voices, and was last updated 5 years, 9 months ago by
Trevor.
-
Anonymous(Private) December 18, 2020 at 5:50 pm #270347
I’ve got my search and filter setup working perfectly on my front page (within Oxygen). It searchs/filters my CPT no problem.
However when I clicked through to a CPT single page I also have a new searchandfilter form/results here which basically does the same as the front page form but with an hard-coded meta_query to show related CPTs.
I have search results showing on a page but I can’t seem to action any ordering on it. I believe this is due to the ‘Results URL’. If I hard set the URL to one of my CPT urls then it works but, as you can guess, if I visit a different single page that ordering no longer works as the URL has changed.
I’ve tried to implement the below on the page but it doesn’t appear to work.
function dynamic_search_results( $url, $sfid) { //if search form ID = 225, the do something with this query if($sfid==1636) { $url = get_the_permalink(); } return $url; } add_filter( 'sf_ajax_results_url', 'dynamic_search_results', 10, 2 );Can you give some guidance on how to setup a results with a dynamically changing URL.
Hope the above makes sense.
Thanks.
Anonymous(Private) December 21, 2020 at 12:17 pm #270482I’ve managed to sort this and hopefully it will help someone who comes across this.
In order to be able to use the sf_ajax_results_url (or any of the url filters) it would appear that there is a check in the code to check if the search form has a ‘Results URL’ set. If it doesn’t then it doesn’t bother to kick in the URL filters. Purely because this filter is to ‘Modify’ URLs (as you say in the docs – apologies I missed this), however I wanted to set the URL completely with ‘get_the_permalink()’.
So….make sure you set a ‘Results URL’ in your searchform in order for your filter to be able to modify/override it.
Great plugin – works perfectly with Oxygen btw 🙂
-
AuthorPosts