Forums Forums Search & Filter Pro SF Pro fails to initialize when having parameters that finds 0 results

Viewing 8 posts - 1 through 8 (of 8 total)
  • Anonymous
    #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?

    Anonymous
    #206422
    This reply has been marked as private.
    Trevor
    #206431

    As 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.

    Anonymous
    #206435
    This reply has been marked as private.
    Anonymous
    #206437

    How come then the link I sent works? Without going through the archive page first?

    The only difference is that this one has results.

    Anonymous
    #206439

    Ok, I guess it’s because WP changes the template to search.php, or index.php when there are no results.

    I wonder how could I force my cpt archive page to be the searchp.php for those results…

    Trevor
    #206440

    It 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) to ON

    And then in the Form UI:

    In each field set Hide Empty to ON

    Anonymous
    #206481

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

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