Forums Forums Search Search Results for 'sf_edit_query_args'

Viewing 10 results - 21 through 30 (of 175 total)
  • Author
    Search Results
  • #249021

    Anonymous
    Inactive

    Hello!

    From what I’ve seen in other forum posts, geolocation search functionality is not yet available.

    We are planning to implement it ourselves, but I would like you to confirm if I could do it with the filters available in your plugin.

    First of all, you would need to include a new field in the form, with a Km distance selector. With which filter could I do it? I have not seen this specifically in the documentation

    Secondly, for searches I have seen that I could use a plugin like this: https://gschoppe.com/wordpress/location-searches/ that extends the WP Query class and then use your sf_edit_query_args filter to add the filter for X km away from the user’s location. Have you done any tests with this type of systems? Would it work well in conjunction with your plugin?

    I await your response, thank you very much!

    #248198

    Ross
    Keymaster

    Hi Boris

    So I took another look today, and now it doesn’t show any result at all….

    I have no idea whats going on, but changes are being made, and I am unable to keep track of this / support this.

    I have once again, disabled the theme, and found things to be working better, which leads me to believe code changes are occuring to the theme.

    Anyway, now I have reduced your search form back to basics, and we are least getting correct results for the slider, I am analysing the dates.

    So.. from what I can see the logic is wrong for your date field.

    You want the user to search for dates, but exclude unavailable dates?

    Well, what you have done is a create a date range field, that searches FOR unavailable dates.

    What you would need to do, is have some post data, with AVAILABLE dates, (even if that is some fake value, such as available from 10 years ago, and available 10 in years in the future – and use that as a min / max for your field)

    Then you will need to use our filter sf_edit_query_argshttps://searchandfilter.com/documentation/action-filter-reference/#edit-query-arguments

    And create a meta query, that excludes unavailable dates from the query. This will be quite complicted to achieve, however, your developer should be able to tackle this.

    Let me know if there is any confusion on the above.

    A request please, if we are going to continue working on this issue, please do so using staging, the default theme, my test search form, and using my results template that I added to the default theme (which outputs the necessary data for me to see whats happening) and DO NOT make any code changes to this theme (if you have to, to add the sf_edit_quer_args filter, please explain clearly what was changed and where).

    Thanks


    Anonymous
    Inactive

    The code got all mixed up, so here I have posted it again
    I have couple of issues
    See this page
    https://acu2020dev.wpengine.com/story
    I have created a page template and added the shortcodes

    echo do_shortcode('[searchandfilter id="133"]');
    echo do_shortcode('[searchandfilter id="133" show="results"]');

    I am showing a featured post first and then I am showing the listing
    As I dont want to show the featured post I added the following code

    function filter_function_name( $query_args, $sfid ) {
    //echo “Coming here”;
    
    //if search form ID = 225, the do something with this query
    if($sfid==133)
    {
    //modify $query_args here before returning it
    if (is_page_template(‘page-templates/stories.php’)) {
    //echo “This is “.get_queried_object_id();
    $featured_story = get_field(“featured_story_landingpage”,get_queried_object_id());
    $exclude = array($featured_story->ID);
    $query_args[‘post__not_in’] = $exclude;
    }
    }
    
    return $query_args;
    }
    
    add_filter( ‘sf_edit_query_args’, ‘filter_function_name’, 20, 2 );

    This works alright when the page is loaded, but when I click the Clear filter button or when a category is selected, the above exclusion is ignored and the featured post is shown in the listing
    What am I doing wrong? or is this a bug in the plugin?
    Also how can I show a numbered pagination?
    regards


    Anonymous
    Inactive

    I have couple of issues
    See this page
    https://acu2020dev.wpengine.com/story
    I have created a page template and added the shortcodes

    echo do_shortcode('[searchandfilter id="133"]');
    echo do_shortcode('[searchandfilter id="133" show="results"]');

    I am showing a featured post first and then I am showing the listing
    As I dont want to show the featured post I added the following code

    function filter_function_name( $query_args, $sfid ) {
      //echo "Coming here";
    
      //if search form ID = 225, the do something with this query
      if($sfid==133)
      {
        //modify $query_args here before returning it
        if (is_page_template('page-templates/stories.php')) {
            //echo "This is ".get_queried_object_id();
            $featured_story = get_field("featured_story_landingpage",get_queried_object_id());
            $exclude = array($featured_story->ID);
            $query_args['post__not_in'] = $exclude;
        }
      }
    
      return $query_args;
    }
    
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );

    This works alright when the page is loaded, but when I click the Clear filter button or when a category is selected, the above exclusion is ignored and the featured post is shown in the listing
    What am I doing wrong? or is this a bug in the plugin?
    Also how can I show a numbered pagination?
    regards


    Anonymous
    Inactive

    I used this just to accomplish the first step:

    function mk_purchased_filter_function( $query_args, $sfid ) {

    //if search form ID = 225, the do something with this query
    if($sfid==62057)
    {

    //modify $query_args here before returning it
    $include = array(154400,148684);
    $query_args[‘post__in’] = $include;
    }

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

    ____________________

    BUT: It does not influence my results. Maybe because Relevanssi is used for the filter, too?
    Or is there any other explanation?

    [searchandfilter id=”62057″]
    [searchandfilter slug=”woocommerce-shop”]

    #242872

    In reply to: A third sort order?


    Anonymous
    Inactive

    Nevermind. I didn’t realize I had to also manually add the meta_query to get the search order to work. Here is my working code:

    function filter_function_name( $query_args, $sfid ) {
    	
    	//if search form ID = 225, the do something with this query
    	if($sfid==23142) {
    		
    	     $query_args["meta_query"] = array(
    	        'relation' => 'AND',
    	        'subject_code' => array(
                    'key'       => 'subject_code',
                    'compare'   => 'EXISTS',
                ),
                'course_number' => array(
                    'key'       => 'course_number',
                    'compare'   => 'EXISTS',
                ),
                'start_date' => array(
                    'key'       => 'start_date',
    		'compare'   => 'EXISTS',
                ),
    	    );
    	    
    		$query_args["orderby"] = array(
            	'subject_code'       => 'asc',
            	'course_number'       => 'asc',
            	'start_date'       => 'asc',
    		);				
    	}
    	
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );
    

    Please feel free to close this ticket. Thank you!

    #242855

    In reply to: A third sort order?


    Anonymous
    Inactive

    Thank you. I restored the Posts settings to the default order and used the following code, which is not affecting the sort order:

    
    function filter_function_name( $query_args, $sfid ) {
    	
    	if($sfid==23142) {
    	
    		$query_args["orderby"] = array(
            	'subject_code'       => 'asc',
            	'course_number'       => 'asc',
    			'start_date'     => 'asc',
    		);				
    	}
    	
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );

    It works if I set just a single order like so:

    
    function filter_function_name( $query_args, $sfid ) {
    	
    	if($sfid==23142) {
    	
    		$query_args["orderby"] = 'subject_code';		
    	}
    	
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );

    Do I need to format the $query_args differently? That’s how I do it in a regular WP_Query…

    Thank you!

    #242232

    Anonymous
    Inactive

    Hi there,
    we would like to add a reltion OR about two field.
    We can’t set it in admin panel so we try to integrate it by php.
    In function.php we add this:

    function filter_results( $query_args, $sfid ) {
    	if($sfid==3981) {
    	$query_args = array(
    	    "meta_query" => array(
                        'relation' => 'OR',
                        array(
                            'key' => 'immobile_disponibile',
                            'compare' => 'NOT EXISTS',
                        ),
                        array(
                            'key' => 'immobile_disponibile',
                            'value' => '1',
                            'compare' => 'NOT LIKE',
                        ),
                    ),
    		"meta_key" => "immobile_disponibile",
    		'orderby' => 'menu_order',
    		"order" => "ASC",
                 );	
    	}
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_results', 20, 2 );

    But… not work.

    #242101

    Ross
    Keymaster

    No not really – we don’t have much in terms of devs accessing our functions to do DB queries etc our way – so so the sf_edit_query_args is usually the way to go.

    If your meta query requires a meta key to be an exact value, I can provide some code to set this in the query which should be much faster – its a bit clunky (we hope to improve this) but it taps in to our tables for a performance boost.

    Let me know what you’re trying to do (share the snippet of code if you like)

    Thanks

    #242002

    Ross
    Keymaster

    Hi Keith

    The filter is sf_apply_filter_sort_post__in

    $post__in = apply_filters('sf_apply_filter_sort_post__in', $this->query_args['post__in'], $this->query_args, $this->sfid);

    Which takes an array of post IDs (the results S&F has found) and must return those posts.

    You’ll then have to disable sorting and sort by post__in in the query (actually, you might be able to leave this set as “default” ordreing in your search form options), you can use the sf_edit_query_args filter to do this.

    If you’re going to follow the link above exactly, the JOIN option might work for you anyway, but there’s two potential approaches for you to try.

    Thanks

Viewing 10 results - 21 through 30 (of 175 total)