Support Forums

The forums are closed and will be removed when we launch our new site.

Looking for support? You can access the support system via your account.

Forums Forums Search & Filter Pro Load defaults on page load

Viewing 10 posts - 1 through 10 (of 10 total)
  • Christian Galster
    #35588

    Hi, lets say i have different pages: dogs, cats and snakes.

    When i open the dogs site the searchform should only load all dogs results.

    Could this be done?

    I want to insert the search form into a theme template. The data (dogs, cats, snakes) are stored in custom fields.

    It should work like: If the current page has as custom field “dogs”, load only dogs results.

    Thx.

    Ross Moderator
    #35589

    Hey Christian

    Can you explain in more details. You are using Dog page and dog site interchangeably.

    Can you be specific what kind of setup you want this to occur on?

    It is possible to do something similar, but this is only on tag/category/taxonomy archives.

    Thanks

    Christian Galster
    #35677

    Hi, when i insert the search result shortcode on the dog page, it should only load the dog results on page load and not all results = dogs, cats and snakes.
    Cheers Chris

    Christian Galster
    #35679

    I found the option, thx: Detect defaults from current page

    Christian Galster
    #36563
    This reply has been marked as private.
    Ross Moderator
    #37039

    Hey Christian

    Sorry for the delay.

    I see what you mean, you want it so that when you “detect defaults” it also applies that criteria to the search results too?

    I’m thinking of adding this as an additional setting.

    Thanks

    Christian Galster
    #37053

    Ok, thanks

    Christian Galster
    #41476

    Hi, are there any news or perhaps you have an idea / hint how i can reolve this?

    Ross Moderator
    #41753

    Hi Christian

    I have not yet had chance to implement this feature – as mentioned it only works with archives at the moment – I have just realised though if you are a dev and can do some coding this may already be possible using a filter:

    http://www.designsandcode.com/documentation/search-filter-pro/action-filter-reference/#Edit_Query_Arguments

    So in there you would manually check to see if the current page/post has a specific category:

    https://codex.wordpress.org/Function_Reference/has_category

    if(has_category( 'dogs', get_the_ID()))
    {
    
    }

    And if so, modify the S&F query to only look inside that category

    $query_args['category_name'] = "dogs"

    So putting it all together:

    function update_search_category( $query_args, $sfid ) {
    	
    	//if search form ID = 225, the do something with this query
    	if($sfid==225)
    	{
    		//here we check to see value is associated with the page
    		
    		if(has_category( 'dogs', get_the_ID()))
    		{
    			$query_args['category_name'] = "dogs"
    		}
    		else if(has_category( 'cats', get_the_ID()))
    		{
    			$query_args['category_name'] = "cats"
    		}
    		else if(has_category( 'snakes', get_the_ID()))
    		{
    			$query_args['category_name'] = "snakes"
    		}
    	}
    	
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'update_search_category', 10, 2 );

    One big caveat I just realised, you may have to disable ajax – this is because an ajax request gets sent off somewhere else, and I think has_category will never give the correct result in an ajax request.

    Thanks

    Christian Galster
    #41763

    Great, i will test this. Thx for your help.

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

The topic ‘Load defaults on page load’ is closed to new replies.