Forums Forums Search Search Results for 'sf_edit_query_args'

Viewing 10 results - 121 through 130 (of 175 total)
  • Author
    Search Results
  • #127149

    Anonymous
    Inactive

    I have a filter set up to find all posts with a relationship to an ACF called “people”, it returns all results with a relationship to a “person” post but I would also like to return the “person” post itself in the search results.

    What is the easiest way to include it in my results?
    I have tried something like this:

    function people_filter( $query_args, $sfid ) {
        if($sfid == 7287)
        {
        	if ($_GET["_sfm_people"] != "") {
          		$query_args['p'] = intval($_GET["_sfm_people"]);
      	}
        }
        return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'people_filter', 10, 200 );

    But this returns the “person” post only, I would instead like to add it to the already compiled results.

    #125885

    Trevor
    Participant

    The first thing to do is, in the code, before you make a change, use the PHP print_r function to output the query array to the screen, and that, after you modify it, do the same again, and compare the arrays. Like this:

    echo '<pre>',print_r($sf_current_query,true),'</pre>';

    I have not actually used the sf_edit_query_args function myself.


    Anonymous
    Inactive

    Hi there I recently followed the example https://support.searchandfilter.com/forums/topic/null-fields-not-returning-results/ as I have an identical issue.

    I used this code pretty much verbatim and a print_r shows all the range fields have been removed from $sf_current_query, HOWEVER the search still behaves as though they are still there and is returning 0 results. If I manually edit the search URL it works fine.

    How do I make sf_edit_query_args actually change the search?

    Thanks,

    Caroline

    #125290

    Trevor
    Participant

    I cannot claim to be much better. You would need to search the forums for what other users have posted:

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

    #125071

    Anonymous
    Inactive

    Hi,

    I use two ACF fields (height and width) in a S&FPro search form. I want to make a calculation (height x width) before I hit search and want to use the result of that calculation in the search throught the field with the name ‘surface’. Is that possible with the hook sf_edit_query_args?

    Can you show me an example on how to do that?

    Kind Regards,

    Peter

    #124848

    Anonymous
    Inactive

    Hi Trevor.

    I tryed using print_r and var_dump in functions.php but nothing is showing up on front-end. Like below:

    
    
    function filter_function_name( $args, $sfid ) {
    
    		//if search form ID = XX, the do something with this query
    		if ( $sfid == 2817 ) {
    
    			var_dump($args['post__in']);
                            print_r($args['post__in']);
    
    		}
    
    		return $args;
    	}
    	add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 200 );
    

    I tryed using var_dump($args['post__in']); in my custom page template and it returns NULL.

    #122190

    Anonymous
    Inactive

    Hi Trevor,

    We renewed our license. Thanks for the reminder!

    I’m trying to walk through the doc you shared and having a little trouble. Essentially, I just want to say that for Search Form 2051 the Category should always be All Items. Even when a user has selected a category that is being used with the other Search result filter on the page.

    Here’s the code from the doc with the appropriate Search Form ID:

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

    I’ve tried to figure out the syntax for saying Category == All without luck.

    Would appreciate your help.

    Thanks!

    #114312

    Anonymous
    Inactive

    Hello :)!

    I modified the main query for the posts of the custom post type archive with the filter ‘pre_get_posts’ changing the ‘post__in’ array of the query. The filtering is working, but the count number isn’t correct.

    Maybe it’s because of the search&filter cache? Can you tell me how to modify the posts delivered to the search form so that the count is working? It seems that setting my own posts in “$query_args[‘post__in’]” within a “sf_edit_query_args”-filter is not working. What do I wrong?

    And when V3 is coming?

    Thank you!

    #99219

    Anonymous
    Inactive

    Hi Trevor,
    some of my WooCommerce products have a meta key “_tribe_event_starttime” and with your plugin I have setup an AJAX filter ordering these products by that meta key.
    Everything was fine for weeks but today I realized that the order has fallen back to the WC default (creation) “date”. You can see the result list by clicking on one of the big images on the top.

    https://obsthof-am-steinberg.de/produkt-kategorie/event-feste-kinder-musik/

    As you can see the AJAX requests has the GET parameter orderby=date and I tried to alter this order by hooking into your filter which I found here on your website:

    // alter query for search & filter results
    add_filter( ‘sf_edit_query_args’, ‘sf_orderby_eventdate’, 10, 2 );
    function sf_orderby_eventdate ($query_args, $sfid) {
    if ($sfid == 6047) {
    $query_args[“meta_key”] = ‘_tribe_event_starttime’;
    $query_args[“order_by”] = ‘meta_value’;
    $query_args[“order”] = ‘ASC’;
    }
    return $query_args;
    }

    Without success. I have installed WP Super Cache last week. Could this be the reason? Is there anything I missed or doing wrong?

    Thank you for your support!
    Oliver

    Now I am

    #98807

    Anonymous
    Inactive

    Wooo, that got it. Thank you for your patience.

    For anyone else with this issue please see my code below. Probably not perfect but it works. 🙂

    // Exclude the default range values from the search as they are meaning the search returns no results
    
    function remove_default_range( $query_args, $sfid ) {
    	
    	//if search form ID = 225, the do something with this query
    	if($sfid==25 && $query_args)	{
    		if((isset($query_args['meta_query']))&&(is_array($query_args['meta_query']))) {
    			global $searchandfilter;
    			$sf_current_query = $searchandfilter->get(25)->current_query()->get_array();
    			/* echo "<pre>";
    			print_r($sf_current_query);
    			echo "</pre>";*/
    
    			echo $sf_current_query['_sfm_minimum_per_round'][0]['value'];
    
    			if($sf_current_query['_sfm_minimum_per_round'][0]['value'] == '0' && $sf_current_query['_sfm_minimum_per_round'][0]['value'] == '50000') {
    				unset($sf_current_query['_sfm_minimum_per_round']);
    			}
    
    			if($sf_current_query['_sfm_minimum_per_season'][0]['value'] == '0' && $sf_current_query['_sfm_minimum_per_season'][0]['value'] == '1000000') {
    				unset($sf_current_query['_sfm_minimum_per_season']);
    			}
    
    		}			
    	}
    
    	
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'remove_default_range', 20, 2 );
Viewing 10 results - 121 through 130 (of 175 total)