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 - 11 through 20 (of 205 total)
  • Author
    Search Results
  • #272324

    Richard Hartley
    Participant
    This reply has been marked as private.
    #271651

    Ross
    Keymaster
    This reply has been marked as private.
    #271205

    Richard Hartley
    Participant

    Hi guys,

    Not the most elegant solution, I suspect, but I have this code correctly pulling in the right values from the slug and parsing them. In the end I opted to filter by the category of the portfolio items as that tends to be more reliable than some of the other meta.

    I’m not sure why, but even though the form is set up to return 42 results, the page only ever displays 10.

    If I add nopaging=>true, to the query I get all results.

    Of course ideally I’d like to load them via ajax as the user scrolls. Do I need to add anything extra to this query, or pass any other variables to achieve that?

    Many thanks!

    The code is here:

    function filter_function_name( $query_args, $sfid ) {
    
    global $post;
    $slug = $post->post_name;
    $sluglist = explode("-", $slug);
    $orientation = $sluglist[0];
    unset($sluglist[0],$sluglist[1],$sluglist[2]);
    $location = implode("-", $sluglist);
    
    if($sfid=="28441"){
    
    $query_args = array(
    'post_type' => 'portfolio',
    'portfolio_category' => "$orientation + $location"
    
    );
    }
    
    return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );
    #270938

    Ross
    Keymaster

    Hi Richard

    I’m having a look through this ticket, and if I understand correctly, the first task we need to solve is how to alter the query / restrict things conditionally.

    I think we were on the right path, with using the filter sf_edit_query_args but the implementation doesn’t look right from what I can see.

    So, to explain, our filter, sf_edit_query_args is just a fancy filter for editing query args that get passed into the new WP_Query( $query_args ); we do for our queries (there is some other stuff going on, but that’s the core of it).

    What that means is, the structure of $query_args must match those of a WP_Query – fortunately, something well documented here:
    https://developer.wordpress.org/reference/classes/wp_query/

    What we need to understand first is, what type of data is orientation?

    Is it custom field / post meta? If so, we can follow the instuctions here:
    https://developer.wordpress.org/reference/classes/wp_query/#custom-field-post-meta-parameters

    Assuming your meta key is orientation then we can do something like:

    function filter_function_name( $query_args, $sfid ) {
    	
    	//if search form ID = 27601, the do something with this query
    	if($sfid==27601)
    	{
    		//modify $query_args here before returning it
    		$query_args['meta_key'] = 'orientation';
    		$query_args['meta_value'] = 'straight';
    	}
    	
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );

    Let me know how you get on with that!

    Best

    #270640

    Richard Hartley
    Participant
    This reply has been marked as private.
    #270521

    Ross
    Keymaster
    This reply has been marked as private.
    #269971

    Elena Politi
    Participant

    Thanks maybe that the thing, but I am not very expert and I don’t know how to use it.

    If I modified the function you suggest and I var_dump the results, I find exactly the list of post I should have, but still the filter doesn’t work

    function filter_function_name( $query_args, $sfid ) {
    	
    	//if search form ID = 225, the do something with this query
    	if($sfid==225)
    	{
    	$posts = get_posts($query_args);
    	$today_year = date('yy');
    	$two_years_ago = $today_year - 2;
    	$current = array();
    
    		foreach( $posts as $post ) {
    			$meta = get_post_meta($post->ID);
    
    				$acf_year = $meta['anno'][0];
    				if($acf_year < $two_years_ago) {
    				$current[] = $post->ID;
    
    		}
    	}
    	$query_args = $current;
    	}
    	
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );

    Could you help through it?

    #269535

    In reply to: Elastic Search/Press


    Trevor
    Moderator

    1. You code the SFID (which is the ID number of the form), like this (assuming the form ID is 1234, but you will need to change that to match the ID of your form):

    function filter_function_name( $query_args, $sfid ) {
    	if($sfid==1234) {
    		$query_args['ep_integrate'] = true;
    	}
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );

    Our function (sf_edit_query_args) passes the sfid itself.

    2. This method works irrespective of the Display Results Method you use in the form.
    3. That is your choice, depending on how you want your site to work, but again this method works irrespective of the Ajax setting in the form.
    4. No need to rebuild the cache.
    5. Not really. There may be a monitor function on your server to show if it is being used.

    #269505

    Ahmed Abouelenin
    Participant

    Hi Trevor,

    I have Elastic search setup on server and working (I tested it with different queries). I also installed ElasticPress plugin. I would like now to integrate it with S&F. I read these two posts:
    https://support.searchandfilter.com/forums/topic/algolia-vs-elastic-search-vs-search-filter-pro/
    https://support.searchandfilter.com/forums/topic/working-with-elasticpress-elasticsearch/

    But could you please give more details how to use the sf_edit_query_args?

    1) I am putting it in functions.php of the child theme but how the sfid is passed to it (is there a way to make sure it is passed correctly to the function)?

    2) I am using for Display Results “Using shortcode”, and I am customising the results as mentioned here:
    https://searchandfilter.com/documentation/search-results/using-a-shortcode/#customising-the-results
    should I use another Display results method?

    3) I am using “Load results using Ajax”, should I disable it?

    4) should I rebuild the cache of S&F after adding the above code to functions.php?
    (Note I was using Relevanssi before but I disabled it now).

    5) Is there a way to test that the s&F is using ElasticPress?

    Thanks,
    Ahmed

    #267895

    In reply to: Wrong attribute order


    Trevor
    Moderator

    There is not an easy way to do this. You would need use this filter in some code that you would insert in your child theme functions.php file:

    https://searchandfilter.com/documentation/action-filter-reference/#edit-query-arguments

    As there are only four values, the easiest code would be to create a new array for that field and return that array to the form. This forum search should yield some code snippets:

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

Viewing 10 results - 11 through 20 (of 205 total)