Forums Forums Search & Filter Pro Conditional tags do not work when using a template as a result page

Viewing 6 posts - 1 through 6 (of 6 total)
  • Anonymous
    #21597

    Hello,

    I am using a custom template to display the search results, archive-project.php in my case.
    The problem is that, although the template is rendered, is_post_type_archive('project') is false and is_home() is true.

    This is important in my project because I am enqueueing scripts and styles depending on these Conditional Tags

    Any solution/workaround?

    Ross Moderator
    #21604

    Hi Marc

    S&F doesn’t play with existing template tags but we have our own if you need to detect:

    global $sf_form_data;
    if ($sf_form_data->is_valid_form())
    {//make sure this is a valid search form
    
    	//do stuff
    }

    Just to let you know this will be changing in S&F 2.0 – (I think it will only be the renaming of $sf_form_data to $searchandfilter

    Thanks

    Anonymous
    #21699

    OK thank you, I can manage with that.
    Just 2 things:

    1. You might want to do a shorthand function is_sf_form(){ return $sf_form_data->is_valid_form(); } (avoids renaming problems in this case)
    2. wordpress conditional tag is_home() continues to be true in my archive-project.php template i use to display the form results, so for conditionally enqueueing scripts in the blog page I am now using is_home() && !is_sf_form()

    Best!

    Anonymous
    #21704

    I just noticed that $sf_form_data->is_valid_form() returns true in the home page (when is_front_page() == true), which is not what i want. So i changed my function to:

    function is_sf_form(){
    	global $sf_form_data;
    	global $wp_query;
    	$search_query = $wp_query->query; 
    	return $sf_form_data->is_valid_form() && !empty($search_query);
    }
    Ross Moderator
    #21789

    Thanks Marc I’ll look in to that

    I’m looking into making this stuff like this a bit easier in 2.0!

    Anonymous
    #21790

    Looking forward to seeing it! 🙂

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