-
Search Results
-
Hello,
So I have 2 S&F forms on my pages (different results pages). Is it possible to pass the query from my main text search to a sidebar filters S&F form I have? The filters on the left live on results page from the main search bar, and if you try to use them they reset the query from the text search (which makes sense technically). I am wondering if there is a way that if a user hits ones of those filters I can pass the query from the other S&F form?
I saw this:
function filter_function_name( $query_args, $sfid ) {
if ( is_search() ) {
//var_dump($sf_current_query);
}//if search form ID = 225, the do something with this query
if($sfid==225)
{
//modify $query_args here before returning it
$query_args[‘somearg’] = ‘newvalue’;
}return $query_args;
}
add_filter( ‘sf_edit_query_args’, ‘filter_function_name’, 20, 2 );But wasn’t sure if that was the right path to grab the current query and pass it along to the other form.
Thank you!
Topic: Search by geolocation
Hello!
From what I’ve seen in other forum posts, geolocation search functionality is not yet available.
We are planning to implement it ourselves, but I would like you to confirm if I could do it with the filters available in your plugin.
First of all, you would need to include a new field in the form, with a Km distance selector. With which filter could I do it? I have not seen this specifically in the documentation
Secondly, for searches I have seen that I could use a plugin like this: https://gschoppe.com/wordpress/location-searches/ that extends the WP Query class and then use your sf_edit_query_args filter to add the filter for X km away from the user’s location. Have you done any tests with this type of systems? Would it work well in conjunction with your plugin?
I await your response, thank you very much!
I have couple of issues
See this page
https://acu2020dev.wpengine.com/story
I have created a page template and added the shortcodesecho do_shortcode('[searchandfilter id="133"]'); echo do_shortcode('[searchandfilter id="133" show="results"]');I am showing a featured post first and then I am showing the listing
As I dont want to show the featured post I added the following codefunction filter_function_name( $query_args, $sfid ) { //echo "Coming here"; //if search form ID = 225, the do something with this query if($sfid==133) { //modify $query_args here before returning it if (is_page_template('page-templates/stories.php')) { //echo "This is ".get_queried_object_id(); $featured_story = get_field("featured_story_landingpage",get_queried_object_id()); $exclude = array($featured_story->ID); $query_args['post__not_in'] = $exclude; } } return $query_args; } add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );This works alright when the page is loaded, but when I click the Clear filter button or when a category is selected, the above exclusion is ignored and the featured post is shown in the listing
What am I doing wrong? or is this a bug in the plugin?
Also how can I show a numbered pagination?
regardsHowdy,
This was originally going to be a support question, but I ended up finding a way to make it work for me. if anything, I’d love feedback on whether or not you had a better method. Otherwise, I’m dropping my code snippet here for other users to find.
Woocommerce has a custom theme support for theme developers that allows for specifying the number of rows and columns on a catalog page. https://docs.woocommerce.com/document/woocommerce-theme-developer-handbook/#section-7
In Search & Filter Pro, there is a setting to specify the results per page, which will completely override this customizer setting.
Here is the code snippet I used to get around this:
function prefix_filters_post_count( $query_args, $sfid ) { // If search form ID = 150, the do something with this query. edit to your form ID. if ( 150 === $sfid ) { if ( function_exists( 'wc_get_theme_support' ) ) { $product_grid = wc_get_theme_support( 'product_grid' ); $rows = isset( $product_grid['default_rows'] ) ? get_option( 'woocommerce_catalog_rows', absint( $product_grid['default_rows'] ) ) : 5; // 5 rows as a fallback $columns = isset( $product_grid['default_columns'] ) ? get_option( 'woocommerce_catalog_columns', absint( $product_grid['default_columns'] ) ) : 3; // 3 cols as a fallback $count = max( 1, $rows * $columns ); // return rows*columns, or fallback to 1 in case of error $query_args['posts_per_page'] = $count; } } return $query_args; } add_filter( 'sf_edit_query_args', 'prefix_filters_post_count', 20, 2 );