-
AuthorSearch Results
-
April 26, 2019 at 11:32 am #209421
TrevorParticipantI would have done this:
function change_sf_results_url( $url, $sfid) { //if search form ID = 225, the do something with this query if($sfid==922) { $url = add_query_arg($url, 'tab', '#promo'); return $url; } } add_filter( 'sf_results_url', 'change_sf_results_url', 10, 2 );
April 26, 2019 at 11:27 am #209417
AnonymousInactiveI have this:
function change_sf_results_url( $url, $sfid) { //if search form ID = 225, the do something with this query if($sfid==922) { $url = add_query_arg('tab', '#promo', $url); return $url; } } add_filter( 'sf_results_url', 'change_sf_results_url', 10, 2 );
Now url looks like:
https://xxx.xxx/place/?tab=#promo&_sfm_choice=red
It should be:
‘
https://xxx.xxx/place/?_sfm_choice=red&tab=#promo
Is it possible?
November 2, 2018 at 10:44 am #192563In reply to: Search & filter delete the lang parametre in url
AnonymousInactiveThank you Ross! Now my code work perfectly.
Here it is :function modify_sf_results_url( $url, $sfid ) { //We stock the current language in a variable $current_and_original = weglot_get_current_and_original_language(); $current_language = $current_and_original['current']; //If current language is German, we use the URL: /de/references if($current_language == 'de'){ $url = home_url('de/references/'); } return $url; } add_filter( 'sf_results_url', 'modify_sf_results_url', 10, 2 );
Thank a lot for your help !
November 1, 2018 at 7:06 pm #192536In reply to: Search & filter delete the lang parametre in url
RossKeymasterHi Jean-Francois
So I had another look and I think I’ve found a quick fix.
Rather than asking WEGLOT what the language is and doing something complicated, we can just choose to modify the results URL for your German search form only.
This code should work but is untested:
function modify_sf_results_url( $url, $sfid ) { if($sfid===228){ //then we know the search form is the german search form (228), and we want to use the URL: /de/references $url = home_url('de/references/'); } return $url; } add_filter( 'sf_results_url', 'modify_sf_results_url', 10, 2 );
Let me know if that works, or if not, and I’ll take a look at what its doing.
Thanks
October 25, 2018 at 12:05 pm #191818In reply to: Search & filter delete the lang parametre in url
AnonymousInactiveThank Trevor, no problems 😉
I have an idea to make search and filter work with WEGLOT :
WEGLOT has a function that store the current language in a variable :$current_and_original = weglot_get_current_and_original_language();
echo $current_and_original[‘current’];So when I click on the filter button it would be necessary that search & filter adds in the URL the language stored in this variable. Maybe with the filter « Modify URL » : https://searchandfilter.com/documentation/action-filter-reference/
function filter_function_name( $url, $sfid) {
// Process URL here
return $url;
}
add_filter( ‘sf_results_url’, ‘filter_function_name’, 10, 2 );So what i can add in place of // Process URL here I’m really a noob in dev 🙁
September 20, 2018 at 4:18 pm #188946In reply to: Setup Assistance | Search & Filter Pro
TrevorParticipantGrant, Ross has given me this code (goes in the child theme functions.php file), as a function to retain the sort order.
function add_order_to_sf_results_url( $url, $sfid) { // Process URL here if(isset($_GET['order_post'])){ $order_post = sanitize_key($_GET['order_post']); $url = add_query_arg('order_post', $order_post, $url); } return $url; } add_filter( 'sf_results_url', 'add_order_to_sf_results_url', 10, 2 );
June 27, 2018 at 8:35 pm #181437In reply to: List/Grid switcher AJAX
RossKeymasterHi Liam
You can do it by modifying the results URL and adding your param there:
function add_query_arg_to_results_url( $url, $sfid) { // Process URL here return add_query_arg('view', 'grid', $url); } add_filter( 'sf_results_url', 'add_query_arg_to_results_url', 10, 2 );
This is actually not the intended use of this filter, and there will likely be better way to do this in v3 (when it comes out)
Thanks
December 8, 2016 at 8:38 pm #75231
RossKeymasterHi Michael
Yup Trevor is correct.
So for the first question 1)
S&F works great with post type archives (you can see this as a display method in
display results
) but it does not yet fully support taxonomy archives (hence no option).So, when you submit a search, you will find that S&F redirects to a search results page, as opposed to searching within the current taxonomy archive.
There is 1 workaround which you can do to achieve something similar but you have to do 2 things (and to be honest, you need some coding skills):
a) tell S&F to affect/modify the queries on your taxonomy archives
To do this you need to modify your taxonomy archive query, and attachsearch_filter_id
to the query (this tells S&F it is allowed to change these queries according to filtering selections)… so you will need to use the WP filter pre_get_posts.. something like:function add_sf_taxonomy_archive( $query ) { if ( $query->is_tax("taxonomy_name") && $query->is_main_query() ) { $query->set( 'search_filter_id', '1234' ); } } add_action( 'pre_get_posts', 'add_sf_taxonomy_archive');
(replace taxonomy_name with your taxonomy slug, and 1234 with your search form ID)
b) tell S&F which page it should display the results on rather than the default search result page (so, your tax term archive), as
Trevor mentioned you need use our filter to dynamically change this:function update_sf_url( $url, $sfid) { // Process URL here $termname = "termname"; //this needs to by dynamic based on current term //this url structure may not be correct for your setup but it will be something similar return home_url("/taxonomyname/".$termname ); } add_filter( 'sf_results_url', 'update_sf_url', 10, 2 ); add_filter( 'sf_ajax_results_url', 'update_sf_url', 10, 2 );
The url that is returned needs to point to the current taxonomy term URL, what I wrote above is psuedocode really…
I would also recommend to test the above with Ajax disabled for now, if that works then enable and carry on…
I hope that makes sense, if you are not a programmer though, I would say the above is very very difficult to achieve…
Best
February 3, 2016 at 7:53 pm #36149In reply to: Make it compatible for on-fly translation
RossKeymasterCan you try the following in functions.php and send me a link to a page with the search form on?
function change_sf_url( $url, $sfid) { // Process URL here //return $url; return "http://www.google.com/"; } add_filter( 'sf_results_url', 'change_sf_url', 10, 2 ); add_filter( 'sf_ajax_results_url', 'change_sf_url', 10, 2 ); add_filter( 'sf_ajax_form_url', 'change_sf_url', 10, 2 );
This should replace any links with
google.com
– let me know if its not updating and send me a link so I can inspect.Thanks
-
AuthorSearch Results