Forums Forums Search Search Results for 'function sf_results_url'

Viewing 9 results - 11 through 19 (of 19 total)
  • Author
    Search Results
  • #209421

    Trevor
    Participant

    I 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 );
    #209417

    Anonymous
    Inactive

    I 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?

    #192563

    Anonymous
    Inactive

    Thank 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 !

    #192536

    Ross
    Keymaster

    Hi 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

    #191818

    Anonymous
    Inactive

    Thank 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 🙁

    #188946

    Trevor
    Participant

    Grant, 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 );
    #181437

    Ross
    Keymaster

    Hi 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

    #75231

    Ross
    Keymaster

    Hi 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 attach search_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

    #36149

    Ross
    Keymaster

    Can 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

Viewing 9 results - 11 through 19 (of 19 total)