Forums › Forums › Search & Filter Pro › sf_edit_query_args is ignored when the Clear Filters link is clicked
- This topic has 9 replies, 3 voices, and was last updated 3 years, 10 months ago by Ross.
-
Anonymous(Private) June 9, 2020 at 9:29 am #247975
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?
regardsAnonymous(Private) June 9, 2020 at 9:31 am #247976The code got all mixed up, so here I have posted it again
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?
regardsRoss Moderator(Private) June 9, 2020 at 9:32 am #247977Hi Michael
The issue is, in an Ajax request, your test for
is_page_template
will not work.So when you search, an ajax request is sent here:
https://acu2020dev.wpengine.com/?sfid=133&sf_action=get_data&sf_data=results&_sft_category=covid-assistanceis_page_template
I’m assuming will return false, because the data is no longer part of the parent page.Does that make sense?
Best
Ross Moderator(Private) June 10, 2020 at 10:41 am #248179Hi Michael
I’m wondering, if you only show the search results on
https://acu2020dev.wpengine.com/story/
Why do you need to check the template? Can you not just use the
$sfid
and leave out the template code?Currently it’s quite hard to pass variables through to that ajax request – but a way around it is to use another display method (like
custom
) and create your ownnew WP_Query
in your template, this display method does not do ajax requests like the shortcode method (it reload the current page, in the background, which would mean your variables etc would work).Let me know your thoughts.
Thanks
Anonymous(Private) February 20, 2021 at 11:34 pm #275763I Have this same issue.
This works fine on the initial load, but when “clear all filters” via AJAX, the query arg change is not respected.
function sf_filter_query_args( $query_args, $sfid ) { if(!is_library()) { return false; } $tax_count = false; $querystring = false; if(isset($_SERVER) && isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) { $querystring = $_SERVER['QUERY_STRING']; $querystring = removeQueryVar($querystring, 'sort_order'); $querystring = removeQueryVar($querystring, '_sf_ppp'); $querystring = removeQueryVar($querystring, 'sf_paged'); $tax_matches = preg_match_all('(sft)', $querystring, $matches); $tax_count = count($matches[0]); } if((isset($_SERVER) && isset($_SERVER['QUERY_STRING']) && empty($_SERVER['QUERY_STRING'])) || empty($querystring) || $querystring = false) { $args = array( 'posts_per_page' => -1, 'post_type' => array('page', 'people'), ); $myposts = get_posts( $args ); foreach($myposts as $post) { $posts_to_exclude[] = $post->ID; } }
Ross Moderator(Private) February 22, 2021 at 10:44 am #275769Hi Jesse
These support forums are closing – can you open a new ticket via your account?
https://searchandfilter.com/account/support/Please reference this issue also and we will get back to you as soon as possible.
Best
-
AuthorPosts