Forums Forums Search Search Results for 'sf_edit_query_args'

Viewing 10 results - 111 through 120 (of 175 total)
  • Author
    Search Results
  • #134719

    In reply to: user specific results


    Anonymous
    Inactive

    Hello Trevor,

    I’ve tried

    function filter_function_name( $query_args, $sfid ) {
        
        $cat_id = array(1);
    	
    	//if search form ID = 225, the do something with this query
    	if($sfid==32)
        {
            $query_args = array(
    		 'category__in' => array($cat_id),
                );
    	}
    	
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );
    

    Is that right? It returns no results – seems not to extend the query ?

    Best
    P.

    #134020

    In reply to: user specific results


    Trevor
    Participant

    The settings all look OK. Yes, you can do that, see this filter:

    Edit Query Arguments filter

    You will find examples of other users’ usage in this forum by searching for this:

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

    #131892

    Trevor
    Participant

    You would need to be running a child theme, and inside the child theme folder on your server would be a file called functions.php

    Edit that and add the sample code on new lines in the file.

    There are examples of using the code in this forum, using this search:

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

    But I am unable to provide help with the coding. For that you would need to hire a coder.

    #131208

    Anonymous
    Inactive

    I still think it’s me who is making the strange question 😉
    I hope I will give this one a last try before I have to give up, since I cannot help my customer a step further.

    I will give you a step by step list of what I have done and want to have:

    1. I just have a front end search form in which the customer uses two fields to insert the ‘height’ and the ‘width’ of something

    2. I also wnat to use S&F to search/filter on a third field (which does not need to be filled in by the customer, since that field should be the calculation of height x width. It is kind of unlogical to let the user fill in the calculated value of something so simple. Right?

    3. So I don’t need to see all the fields on the screen, I just need to get access to the two fields I mentioned. I found the names of them: _sfm_breedte (width) and _sfm_hoogte (height)

    4. I thought I could use the ‘Edit Query Arguments’ routine, and use it for the ID of my S&F serach (in my case 3954). I thought I could get the field values in that routine and make the needed calculation of the third field value there.

    5. Yes and that field might be made invisible in the front end, since the user does not need to see it. So you in ACF Pro I use the three fields, but only two shown in the search form. Ik hope that makes the appraoch for my request more clear.

    Questions:

    1. Is the routine I want to use the right one?
    2. So, how do I access and get the values of the two defined fields? I don’t need to dispaly them, just use them to make a calculation

    Example of non-PHP code in written words:

    function filter_function_name( $query_args, $sfid ) {

    //if search form ID = xxxx, the do something with this query
    if($sfid==xxxx)
    {
    get me the value of ‘height’

    }

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

    #130222

    Anonymous
    Inactive

    The hook ‘sf_edit_query_args’ allowed me to update meta_query successfully.

    Thanks Trevor!

    #127591

    Anonymous
    Inactive

    Yes it is, the code is as following:

    function sf_filter_query_args($query_args, $sfid) {
        echo '<pre>',print_r($query_args,true),'</pre>';
    
        if ($sfid == 327) {
            add_filter('posts_where', 'acf_posts_where_likes');
    
            $query_args['meta_query'] = array(
                'relation' => 'AND',
                array(
                    'key' => 'likes_%_gebruiker',
                    'value' => '16',
                    'compare' => 'LIKE'
                )
            );
        }
    
        echo '<pre>',print_r($query_args,true),'</pre>';
    
        return $query_args;
    }
    
    add_filter('sf_edit_query_args', 'sf_filter_query_args', 10, 400);
    #127421

    Trevor
    Participant

    You need to output the $query_args array before and after this code, like this:

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

    To see if any change was made. It may be that you need to run the code later, e.g.

    add_filter('sf_edit_query_args', 'sf_filter_query_args', 10, 200);
    

    Anonymous
    Inactive

    Hello guys!

    I have a custom sf_filter_query_args like so:

    function sf_filter_query_args($query_args, $sfid) {
        if ($sfid == 327) {
            add_filter('posts_where', 'acf_posts_where');
    
            $query_args['meta_query'] = array(
                'relation' => 'AND',
                array(
                    'key' => 'likes_%_gebruiker',
                    'value' => '16',
                    'compare' => 'LIKE'
                )
            );
        }
    
        return $query_args;
    }
    
    add_filter('sf_edit_query_args', 'sf_filter_query_args', 10, 2);

    Which works perfectly when I come on the page. It filters succesfully on the meta_query. But when I select a filter it returns all result and not the results where likes_%_gebruiker is 16 + the filters.

    Am i doing something wrong? Can someone help me out?

    Thanks

    #127343

    Anonymous
    Inactive

    It was actually firing too early. Still I can’t seem to add the post to the results.
    Here is my code:

    function people_filter( $query_args, $sfid ) {
       if($sfid == 7287)
        {
        	if ($_GET["_sfm_people"] != "") {
        		array_push($query_args['post__in'], intval($_GET["_sfm_people"]));
        		echo '<pre>',print_r($query_args,true),'</pre>';
      		}
        }
        return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'people_filter', 20, 2 );

    And here is what the print_r is echoing:

    Array
    (
        [paged] => 1
        [search_filter_id] => 7238
        [search_filter_override] => 
        [posts_per_page] => -1
        [post_status] => Array
            (
                [0] => publish
            )
    
        [meta_query] => Array
            (
            )
    
        [post_type] => Array
            (
                [0] => lesson
                [1] => people
                [2] => video
                [3] => image
                [4] => article
            )
    
        [is_search] => 1
        [post__in] => 
    )
    #127340

    Anonymous
    Inactive

    Hmm, I’m getting an empty array. My code:

    function people_filter( $query_args, $sfid ) {
        if($sfid == 7287)
        {
          		echo '<pre>',print_r($query_args,true),'</pre>';
        }
        return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'people_filter', 10, 200 );

    It’s strange because the archive page is displaying results, maybe it’s firing too late?

Viewing 10 results - 111 through 120 (of 175 total)