Search Results for 'sf_current_query get_array'

Forums › Forums › Search › Search Results for 'sf_current_query get_array'

Viewing 10 results – 31 through 40 (of 103 total)
  • Author
    Search Results
  • #222869

    Trevor
    Participant

    To fetch the search terms, the https://searchandfilter.com/documentation/accessing-search-data/ guide is basic but you can extend the idea to grab lots of other data. If you have other filters, then it becomes a little more complex, but I can give you links. This thread might help you:

    https://support.searchandfilter.com/forums/topic/accessing-field-slug-on-search-results/

    … and this search will give similar threads I think:

    https://support.searchandfilter.com/forums/search/sf_current_query+get_array

    Note, if you are using Ajax refreshing of the results, any PHP needs to be inside the Ajax Container, or it will not update.

    You could use this to display the filter array:

    <?php
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1391)->current_query()->get_array();
    echo '<pre>',print_r($sf_current_query,true),'</pre>';
    ?>

    Where the ID needs to match that of your form.

    #221016

    Anonymous
    Inactive

    hi Ross, hi Trevor,

    you guys are really supportive and i read a lot of posts on the forum. i still can’t figure out what i am trying to do alone, so i thought i would reach out.

    1 – latest WP 5.2.3
    2 – S&F Pro
    3 – ACF Pro (latest)
    4 – custom theme from scratch

    on the news search page (which is the standard posts type of WP), i am trying to do this:

    1 – allow a category filter
    2 – a search box
    3 – allow a date range filter with the terms “past month, 6 month, past year, older than 1 year”

    1 and 2, no problem. works perfectly.

    for date range, since that’s not an existing feature, i am trying to trick it to working.

    i read about the action filters, and i read about the various hooks.

    i realize that’s not something that can be done with a regular date field on Post Date.
    so i need to find another way.

    I am able to add a 'date_query' in a sf_edit_query_args function. When I hard code it like that it works just fine. But I want to give the visitor the dropdown that allows that choice.

    I tried to inject a dropdown in the form but it was being ignored by the Ajax function.
    I tried to use a dummy ACF field, called “sf-date-range” which contains the options I want for that (-1 month, -6 month, etc.) and build the date_query from that. I am able to do so with the sf_edit_query_args function, like this:

    
    /* custom search and filter query update based on date range */
    function custom_date_query_for_sf( $query_args, $sfid ) {
    	
    	global $searchandfilter;
    	
    	$sf_current_query = $searchandfilter->get(2467)->current_query();
    	$customFieldsArray = $sf_current_query->get_array();
    	$customHumanDate = $customFieldsArray["_sfm_sf-date-range"]["active_terms"][0]["value"];
    	 
    	//if search form ID = 2467 // news search, the do something with this query
    	if($sfid == 2467)
    	{
    			
    		if ($customHumanDate && $customHumanDate != NULL) { 
    
    				$query_args['date_query'] =  array(array('after' => $customHumanDate,));
    
    			} 
    		
    		echo "<pre>";
    		print_r($query_args);
    		echo "</pre>";  
    	
    	}
    
    	return $query_args;
    
    }
    
    add_filter( 'sf_edit_query_args', 'custom_date_query_for_sf', 20, 2 );
    

    however, since that ACF field is not really being used, the search returns blank since those fields aren’t checked, ever. the query is built ok, and again when I hard code it without the use of that ACF field, works fine:

    this example, hard-coded, returns exactly what’s expected (posts older than 1 year and younger than 2 years) :

    `
    Array
    (
    [paged] => 1
    [search_filter_id] => 2467
    [search_filter_override] =>
    [posts_per_page] => 10
    [post_status] => Array
    (
    [0] => publish
    )

    [category__not_in] => Array
    (
    [0] => 42
    )

    [meta_query] => Array
    (
    )

    [post_type] => post
    [orderby] => Array
    (
    [date] => DESC
    )

    [date_query] => Array
    (
    [0] => Array
    (
    [before] => -1 year
    )

    [1] => Array
    (
    [after] => -2 year
    )

    )

    )
    ‘

    so I know my query works.

    when i use the ACF field to generate the dropdown and make it all Ajax and neat, i don’t get the right results, even though I get the right query built (I have to refresh the screen to see the query, but i see it and it’s good. by the way, can I make the print_r that’s got the query printout ajaxified so that it shows me the right values on form change?)…

    I think the issue is that the ACF field I am using as a dummy dropdown generator is being read and obviously no values are in there since it’s not really being used. I tried to “unset” or “ignore” the ACF field which I only use to make it ajax and friendly…

    do you have a suggestion on how to accomplish what I am trying to accomplish? I know that v3 will allow me to make my own fields (which is what I am trying to do really here but without that) – but that’s not something I can wait on at the moment.

    i can send you a link in private if you want to see what I am doing.

    much appreciated,

    thanks — 

    Kaz


    Trevor
    Participant

    To fetch the search terms, the https://searchandfilter.com/documentation/accessing-search-data/ guide is basic but you can extend the idea to grab lots of other data. If you have other filters, then it becomes a little more complex, but I can give you links. This thread might help you:

    https://support.searchandfilter.com/forums/topic/accessing-field-slug-on-search-results/

    … and this search will give similar threads I think:

    https://support.searchandfilter.com/forums/search/sf_current_query+get_array

    Note, if you are using Ajax refreshing of the results, any PHP needs to be inside the Ajax Container, or it will not update.

    You could use this to display the filter array:

    <?php
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1391)->current_query()->get_array();
    echo '<pre>',print_r($sf_current_query,true),'</pre>';
    ?>

    Where the ID needs to match that of your form.

    #215288

    Trevor
    Participant

    I am not sure if this is what you want. To show the filters, as I said, this requires custom coding when using the current version of Search & Filter Pro. You can access the filter terms though, but would need further PHP work to display them. To fetch the search terms, the

    https://searchandfilter.com/documentation/accessing-search-data/

    guide is basic but you can extend the idea to fetch other filter terms/data. If you have other filters, then it becomes a little more complex, but I can give you links. This thread might help you:

    https://support.searchandfilter.com/forums/topic/accessing-field-slug-on-search-results/

    … and this search will give similar threads I think:

    https://support.searchandfilter.com/forums/search/sf_current_query+get_array+field+%5Bvalue%5D/

    Note, if you are using Ajax refreshing of the results, any PHP needs to be inside the Ajax Container, or it will not update.

    #213328

    Trevor
    Participant

    You can find more details from the filter query array.

    You may need to temporarily output the array to see how to access the term that you want.

    If you add this code to the page, it will output the entire array:

    <?php
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1391)->current_query()->get_array();
    echo '<pre>',print_r($sf_current_query,true),'</pre>';
    ?>

    Anonymous
    Inactive

    I want to get the currently active filter sort label

    I try this

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1391)->current_query();
    
    $array_data = $sf_current_query->get_array();
    $typeOfSearch = $array_data["_sf_sort_order"]["active_terms"][0]["value"];

    but I can’t get the label…


    Trevor
    Participant

    If I understand you correctly, you need to output the currently searched for term(s) on the results page. To an extent, this is limited by how the page is constructed, but as long as you have a PHP template and know how to edit/code that, you should be able to achieve what you want.

    To show the filters, as I said, this requires custom coding when using the current version of Search & Filter Pro. You can access the filter terms though, but would need further PHP work to display them. To fetch the search terms, the https://searchandfilter.com/documentation/accessing-search-data/ guide is basic but you can extend the idea to grab lots of other data. If you have other filters, then it becomes a little more complex, but I can give you links. This thread might help you:

    https://support.searchandfilter.com/forums/topic/accessing-field-slug-on-search-results/

    … and this search will give similar threads I think:

    https://support.searchandfilter.com/forums/search/sf_current_query+get_array+field+%5Bvalue%5D/

    Note, if you are using Ajax refreshing of the results, any PHP needs to be inside the Ajax Container, or it will not update.

    #210744

    Trevor
    Participant

    To showing the filters, this requires custom coding when using the current version of Search & Filter Pro. You can access the filter terms though, but would need further PHP work to display them. To fetch the search terms, the https://searchandfilter.com/documentation/accessing-search-data/ guide is basic but you can extend the idea to grab lots of other data. If you have other filters, then it becomes a little more complex, but I can give you links. This thread might help you:

    https://support.searchandfilter.com/forums/topic/accessing-field-slug-on-search-results/

    … and this search will give similar threads I think:

    https://support.searchandfilter.com/forums/search/sf_current_query+get_array+field+%5Bvalue%5D/

    Note, if you are using Ajax refreshing of the results, any PHP needs to be inside the Ajax Container, or it will not update.

    #209333

    Trevor
    Participant

    I am sorry for the delay. I am working my way through a backlog and I answer posts is oldest last touched order, so yours was still another two or three down the list when you sent that last reply. The standard WordPress would, with your wp_query() array name, look like this:

    Found <?php echo $query_all->found_posts; ?> Results

    As to showing the filters, this is more complex. It would require custom coding when using the current version of Search & Filter Pro. You can access the filter terms though, but would need further PHP work to display them. To fetch the search terms, the https://searchandfilter.com/documentation/accessing-search-data/ guide is basic but you can extend the idea to grab lots of other data. If you have other filters, then it becomes a little more complex, but I can give you links. This thread might help you:

    https://support.searchandfilter.com/forums/topic/accessing-field-slug-on-search-results/

    … and this search will give similar threads I think:

    https://support.searchandfilter.com/forums/search/sf_current_query+get_array+field+%5Bvalue%5D/

    Note, if you are using Ajax refreshing of the results, any PHP needs to be inside the Ajax Container, or it will not update.

    #209306

    Trevor
    Participant

    It would require custom coding when using the current version of Search & Filter Pro. You can access the filter terms though, but would need further PHP work to display them. To fetch the search terms, the https://searchandfilter.com/documentation/accessing-search-data/ guide is basic but you can extend the idea to grab lots of other data. If you have other filters, then it becomes a little more complex, but I can give you links. This thread might help you:

    https://support.searchandfilter.com/forums/topic/accessing-field-slug-on-search-results/

    … and this search will give similar threads I think:

    https://support.searchandfilter.com/forums/search/sf_current_query+get_array+field+%5Bvalue%5D/

    Note, if you are using Ajax refreshing of the results, any PHP needs to be inside the Ajax Container, or it will not update.

Viewing 10 results – 31 through 40 (of 103 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.