Search Results for 'sf_edit_query_args'

Forums › Forums › Search › Search Results for 'sf_edit_query_args'

Viewing 10 results – 31 through 40 (of 203 total)
  • Author
    Search Results

  • 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

    #239148

    Anonymous
    Inactive

    How would I go about adding the To-date into the query? This is the query args that I get when I add the sf_edit_query_args filter (even with dates put in):

    Array
    (
        [paged] => 1
        [search_filter_id] => 144
        [search_filter_override] => 
        [posts_per_page] => 10
        [post_status] => Array
            (
                [0] => publish
            )
        [meta_query] => Array
            (
            )
        [post_type] => cursus
        [post__in] => Array
            (
                [0] => 0
            )
    )

    I can’t see any of the form inputs here, the only thing that seems to change is when I put in a search word, the [s]-arg is added.


    Anonymous
    Inactive

    I’m trying to figure out whether it’s possible to use a single date input as a lower bound for posts containing a ‘start date’ meta, so that if I input for example 2020-04-15 it will return me all posts having a start date of that AND later in the future. Right now it only returns posts having exactly that start date.

    If I add a filter to sf_edit_query_args, I can’t see the date or any meta query arguments entered in the search form, same goes for the sf_main_query_pre_get_posts filter. Is it possible to hook in anywhere to change the meta_compare type of the query for the start date meta key?


    Ross
    Keymaster

    Hi Sigurd

    After scratching my head I managed to figure out the issue.

    We perform our search outside of the regular WP_Query, so if you choose a category in our search form, WP doesn’t actually “know” its restrciting to a specific category, because our search does that, so WP appends the stick post…

    I’ve managed to come up with some code, that add the WP category to the WP_Query (even though our plugin has already restricted the posts to this category), but now WP also knows that at a category restriction is happening, and excludes the sticky:

    add_filter("sf_edit_query_args", "add_wp_category_to_query", 100, 2);
    function add_wp_category_to_query($query_args, $sfid){
    	
    	//if($sfid == 1234){ //you can restrict this behaviour to a search form ID
    	
    	//get user category selection from the search form (ie, detect which categories have been selected)
    	global $searchandfilter;
    	$query_data = $searchandfilter->get($sfid)->current_query();
    	$query_data_array = $query_data->get_array();
    	if(isset($query_data_array['_sft_category'])){
    		$category_values = $query_data_array['_sft_category']['active_terms'];
    		$current_category_ids = array(); //this will contain all the IDs of the categories that have been selected in the search form
    		foreach($category_values as $category){
    			array_push($current_category_ids, $category['id']);
    		}
    		//restrict query to WP category
    		$query_args['category__in'] = $current_category_ids;
    	}
    	//}
    	
    	return $query_args;
    }

    As there may be some small overhead when implementing this code, you can uncomment the first if( line, and restrict this to a specific search form / query.

    I hope that makes sense & works!

    Best

    #237281

    Anonymous
    Inactive

    Hi,

    I created a form that includes post meta fields. I would like it to also include posts that do not have these meta keys at all.
    It is especially a problem because one might use other fields to filter the results, but once the form is submitted the meta fields (range sliders in that case) are taken into account as well, and posts with no meta disappear.
    I tried to use the “sf_edit_query_args” filter, but it seems the meta_query is empty when it is applied…
    maybe I am using it wrong?

    Thank you very much!

Viewing 10 results – 31 through 40 (of 203 total)
Search & Filter Support
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

We also use cookies to store items in your cart as well as allowing your to login on the site.

You can adjust all of your cookie settings by navigating the tabs on the left hand side.

By continuing to use this site, you also agree to our Privacy Policy.