Forums Forums Search & Filter Pro sf_edit_query_args is ignored when the Clear Filters link is clicked

Viewing 10 posts - 1 through 10 (of 10 total)
  • Anonymous
    #247975

    I have couple of issues
    See this page
    https://acu2020dev.wpengine.com/story
    I have created a page template and added the shortcodes

    echo 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 code

    function 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?
    regards

    Anonymous
    #247976

    The 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 shortcodes

    echo 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 code

    function 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?
    regards

    Ross Moderator
    #247977

    Hi 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-assistance

    is_page_template I’m assuming will return false, because the data is no longer part of the parent page.

    Does that make sense?

    Best

    Anonymous
    #247991

    OK will try and let you know
    Will get_queried_object_id() work?

    Anonymous
    #247992

    I feel get_queried_object_id also does not work
    So what can I do to resolve this?
    I hope you understand what I am trying to do

    Anonymous
    #248017

    I just want to get the postid of the page where the shortcodes are added
    Is there anyway to get that ?

    Anonymous
    #248099

    any replies ????

    Ross Moderator
    #248179

    Hi 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 own new 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
    #275763

    I 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
    #275769

    Hi 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

Viewing 10 posts - 1 through 10 (of 10 total)