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 - 31 through 40 (of 205 total)
  • Author
    Search Results
  • #250811

    In reply to: WPBakery extension


    Ross
    Keymaster

    Hi again

    So you would need to use our filter sf_edit_query_args:
    https://searchandfilter.com/documentation/action-filter-reference/#edit-query-arguments

    This allows you access to the query arguments, where you can change things like post type, post status, and do taxonomy and custom field queries.

    It takes the exact same arguments as for a WP_Query- so you can use the docs to know what you can / can’t do:
    https://developer.wordpress.org/reference/classes/wp_query/#taxonomy-parameters

    (The 3rd example shows pretty much what you are trying to achieve)

    You can add the taxonomy parameters to $query_args by doing:
    $query_args['tax_query'] = array( /* your stuff */ );

    You will also want to set relation to OR, as in the third example in the above link.

    Thanks

    #249021

    starenlared
    Participant

    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


    Michael Panetta
    Participant

    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


    Michael Panetta
    Participant

    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


    Miriam Brückner
    Participant

    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”]

    #246081

    In reply to: Custom development


    Philip Cole
    Participant
    This reply has been marked as private.
    #242872

    In reply to: A third sort order?


    Lindsay Sterling
    Participant

    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?


    Lindsay Sterling
    Participant

    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

    MAURO BERETTA
    Participant

    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.

Viewing 10 results - 31 through 40 (of 205 total)