Support Forums

The forums are closed and will be removed when we launch our new site.

Looking for support? You can access the support system via your account.

Forums Forums Search Search Results for 'sf_edit_query_args'

Viewing 10 results - 61 through 70 (of 205 total)
  • Author
    Search Results
  • #213628

    Jordan
    Participant

    TJ, another quick example maybe to help:

    
    function filter_function_name( $query_args, $sfid ) {    
        if($sfid==2978) {
    
         global $arr_product_ids;
    
          $query_args['tax_query'] = array(
            array(
              'key'     => 'post_product',
              'value'   => $arr_product_ids,
              'compare' => 'IN',
            ),
          );
    
        }    
        return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );
    
    #213626

    Jordan
    Participant

    Hi TJ,

    On your second example, did you try adding: global $arr_product_ids within the function too? Your trying to use $arr_product_ids variable.

    
    function filter_function_name( $query_args, $sfid ) {    
        if($sfid==2978) {
    
            global $arr_product_ids;
    
            $query_args['post_product'] = $arr_product_ids;
        }    
        return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );
    
    #212527

    Rebecca Taubert
    Participant

    To be honest I am not sure how to create that function – it’s a bit beyond my abilities.

    I tried this, but it made the search form stop working.
    function filter_function_name( $query_args, $sfid ) {

    //if search form ID = 225, the do something with this query
    if($sfid==26869)
    {
    //modify $query_args here before returning it

    $query_args[‘post_type’] = array( ‘practitioners’ );
    }

    return $query_args;
    }
    add_filter( ‘sf_edit_query_args’, ‘filter_function_name’, 20, 2 );

    Just to simply matters, I have removed all the functions.php code altogether for the time being. As you will see on the page, the pagination does not seem to work with the search form on the page. When I put in a manual pagination link of https://staging-universallifetools.kinsta.cloud/our-teachers/page/2 it works, but the actual pagination buttons do not seem to do anything, just refresh the page.

    #211667

    Ross
    Keymaster

    Hi Michal

    In regards to your original question, about prepending posts to the results array.

    I don’t think it’s possible.

    S&F uses a WP_Query which is the WP way of generating a query, with the results as valid post objects.

    There are no WP_Query params that we can use (in our sf_edit_query_args filters, which is basically a filter for WP_Query args) to do this.

    The only way I could see you doing it, is in your results template.

    You could run a query for the posts you want, and then combine it with the results from S&F.

    I’m afraid achieving this specifically would be out of scope of support, but the above would be the general logic.

    You also mentioned being able to do this only when a specific taxonomy is selected, and that can be done with the info from your second question:

    You wanted to get the IDs of the terms.

    If you use get_array instead of get_field_string you’ll see that taxonomies have IDs as well as slug and label – https://searchandfilter.com/documentation/accessing-search-data/#getan-array-offilterswithvalues-and-labels.

    I hope the above is clear!

    Thanks


    al8t3
    Participant

    Thank you. So stick this in the theme functions, set to the correct form ID and add the same args per my wp_query. So I have ended up with:

    function filter_function_name( $query_args, $sfid ) {
        
        //if search form ID = 225, the do something with this query
        if($sfid == 4672)
        {
            //modify $query_args here before returning it
            $query_args['numberposts'] = -1;
            $query_args['posts_per_page'] = 25;
            $query_args['post_type'] = 'product';
            $query_args['post_status'] = 'publish';
            $query_args['meta_key'] = 'special_offer';
            $query_args['meta_value'] = true;
        }
        
        return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );
    

    I have left the rest of the settings as per my last message (including the wp_query on the special_offers template where I am displaying the products). When I view the page the filters are not populating as expected, I should be seeing options for colour and size but I just see one colour option, which when I apply renders no results.

    Am I doing something else wrong here?

    #207594

    In reply to: Including taxonomies


    Ian Anderson
    Participant

    Thanks Trevor.

    I managed to get it working with this:

    function filter_aus_library ( $query_args, $sfid ) {
    	
    	//if search form ID = 225, the do something with this query
    	if($sfid==14334)
    	{
    		//modify $query_args here before returning it
    		$query_args['tax_query'] = array(
      'relation' => 'OR', 
      array(
        'taxonomy' => 'library_country',
        'terms'    => '1497',
      ),
    	array(
        'taxonomy' => 'library_author',
        'terms'    => '2192',
      )
    );
    	}
    	
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_aus_library', 20, 2 );
    #207512

    Pascal Tatipata
    Participant

    Ok,

    I added the next code to function.php

    function filter_function_name( $query_args, $sfid ) {
    	
    	//if search form ID = 225, the do something with this query
    	if($sfid==6178)
    	{
    		//modify $query_args here before returning it
    		$query_args['orderby'] = 'post_views';
    				
    	}
    	
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 10, 2 );

    But now if I use the filter it is only showing 2 downloads:
    https://www.dl-sounds.com/member/downloads/?sort_order=name+asc&_sfm_bpm=0+1000

    without the filter it is working:
    https://www.dl-sounds.com/member/downloads

    I must be doing something wrong?

    #207161

    Matt
    Participant

    Yes, and the element was removed, but it had no effect on the query. It still processed it as if the element was in the query.

    So I had to work around it by unsetting the element that was set in the $_GET variable. It works for now, but I was sure it would have been straight forward using the sf_edit_query_args function.

    #207114

    Trevor
    Moderator

    I think by custom coding and using our https://searchandfilter.com/documentation/action-filter-reference/#edit-query-arguments filter. I cannot give you a snippet for this, but you might find one by searching this forum:

    https://support.searchandfilter.com/forums/search/add_filter+sf_edit_query_args/

    #207085

    dpolonsky
    Participant

    I commented out the function that used the sf_edit_query_args hook. Then I added the query set to my existing modify_search_results_order function that’s using pre_get_posts after all the query args I already set. For some reason it caused a fatal error regarding memory size. I thought maybe it was the syntax, so I changed it to $query->query_vars['search_filter_id'] = 493580; and that seemed to cause endless looping with constant undefined index errors.

    Am I applying it correctly?

    On my WP admin settings, I have the “Display Results” tab set where the method is “As an archive” and the template options are using a custom template, search.php. No slug set and no ajax.

    Thanks.

Viewing 10 results - 61 through 70 (of 205 total)