Forums › Forums › Search & Filter Pro › SF Pro fails to initialize when having parameters that finds 0 results
Tagged: Initialize, No results, s&f pro
- This topic has 7 replies, 2 voices, and was last updated 5 years, 9 months ago by Anonymous.
-
Anonymous(Private) March 27, 2019 at 4:06 am #206421
Hi. I have a SF Pro filter active on an archive page with many fields.
There’s apartment type radio select field and location dropdown field. If I load up the archive page and select a combination that ends up with 0 results things are fine – just no results are shown.
But if I take that permalink and load it again in a new window, the entire SF Pro doesn’t start. No filters nor anything.
Could you help?
Trevor(Private) March 27, 2019 at 9:31 am #206431As the Display Results method is set to Post Type Archive, it is your theme template that is handling the display. when you do the search as you suggest, it refreshes only a portion of the page and so does not ‘fail’. when you load the page fresh with the filters in the URL, your theme is checking if there are any matching posts and the PHP of the theme does not have any logic to handle ‘No Results’, or at least it does not display anything.
If you wish to allow users to select 0 count options, you would need to edit the theme template in use (make sure you use a child theme to do this) and create HTML structures that emulate the with results structure.
Trevor(Private) March 27, 2019 at 10:15 am #206440It is the logic inside the theme template that the page uses. If it has results, it will work. If it does not have results, it will not. You can set our form to remove any zero results options, to stop this. In the General settings tab:
Set
Auto Count
(both settings) toON
And then in the Form UI:
In each field set
Hide Empty
toON
Anonymous(Private) March 27, 2019 at 12:50 pm #206481The problem was essentially this line in my index.php
get_template_part( 'template-parts/archive', get_post_type() );
get_post_type only echoes the post type if the query contains at least 1 result.
When changing it to
$archivetype = get_post_type(); if (is_archive()){ $queried_object = get_queried_object(); $archivetype = $queried_object->name; } ……… get_template_part( 'template-parts/archive', $archivetype );
It starts to work.
Thanks Trevor for your answers! I think this solves also my previous question which was about weird looking cache page.
-
AuthorPosts