Search Results for 'function sf_edit_query_args'

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

Viewing 10 results – 101 through 110 (of 141 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.

    #126664

    Anonymous
    Inactive

    Hello,

    I am trying to add a custom filter to search a meta field, based on an input field that the user types in.

    function filter_function_name( $query_args, $sfid ) {
    
        //if search form ID = 1880, then do something with this query
        if($sfid==1880)
        {
          //modify $query_args here before returning it
          $meta_query = array(
              'key' => 'NAM-Authors',
              'value' => $query_args['s'],
              'compare' => 'LIKE'
            );
    
          $query_args['meta_query'] = array($meta_query);
    
        }
        return $query_args;
      }
      add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );

    This is not returning the results I am looking for. Any idea what I am doing wrong? Thank you for your time.

    #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.

    #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.

    #124614

    Anonymous
    Inactive

    Hello guys,

    I have exactly the same problem of this topic (resolved):

    https://support.searchandfilter.com/forums/topic/adding-post-ids-to-returned-results/

    I did what you suggest, but it returns all posts instead my array on $args[‘post__in’].

    If I use $args[‘p’] or $args[‘meta_query’] for example, it works fine.

    Here is my code:

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

    Thanks in advance 🙂

    #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!


    Anonymous
    Inactive

    Hello!

    I have a custom page template which has the following args to WP_Query:

    
    $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
    $args = array(
      'post_type'=> 'tarefa',
      'posts_per_page' => 5,
      'order' => 'DESC',
      'author' => $feed_rc,
      'meta_query' => $feed_cd,
      'paged' => $paged,
    );
    $args['search_filter_id'] = 2817;
    $wp_query = new WP_Query( $args );
    

    The problem was it was ignoring my meta_query, showing values from all posts on the filter.

    To solve this, I used the “Edit Query Arguments” filter:

    
    function filter_function_name( $args, $sfid ) {
    
    if ( $sfid == 2817 ) {
    
    $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
    
    $args = array(
      'post_type' => 'tarefa',
      'posts_per_page' => 5,
      'order' => 'DESC',
      'author' => $feed_rc,
      'meta_query' => $feed_cd,
      'paged' => $paged,
    );
    
    }
    
      return $args;
    
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );
    

    And on my custom page template I used only: $args['search_filter_id'] = 2817;

    Well, the filter is recognizing my meta_query and working perfectly now.

    The question:
    Pagination stopped working.
    When I click on 2nd page link, for exemple, it shows that it’s on 2nd page but actually it loads 1st page results. Using AJAX ou not, it doesn’t work.
    Am I doing the right way or is there another way to achieve that?

    Thanks in advance.

    #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 );
    #98705

    Anonymous
    Inactive

    Sorry to bother you, I’m trying to modify the query, however the $query_args[‘meta_query’] is returning a blank array whenever I print it out. This is even after I have altered a field and submitted the form.

    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']))) {
          print_r($query_args['meta_query']);
    		}			
    	}
    	
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'remove_default_range', 20, 2 );
Viewing 10 results – 101 through 110 (of 141 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.