Forums › Forums › Search & Filter Pro › Conditional tags do not work when using a template as a result page
Tagged: archive, conditional tags, custom post type, Template
- This topic has 5 replies, 2 voices, and was last updated 9 years, 3 months ago by Anonymous.
-
Anonymous(Private) July 17, 2015 at 9:28 am #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 andis_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(Private) July 17, 2015 at 12:31 pm #21604Hi 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(Private) July 20, 2015 at 10:57 am #21699OK thank you, I can manage with that.
Just 2 things:- You might want to do a shorthand
function is_sf_form(){ return $sf_form_data->is_valid_form(); }
(avoids renaming problems in this case) - wordpress conditional tag
is_home()
continues to be true in myarchive-project.php
template i use to display the form results, so for conditionally enqueueing scripts in the blog page I am now usingis_home() && !is_sf_form()
Best!
Anonymous(Private) July 20, 2015 at 12:13 pm #21704I 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(Private) July 21, 2015 at 11:51 am #21789Thanks Marc I’ll look in to that
I’m looking into making this stuff like this a bit easier in 2.0!
- You might want to do a shorthand
-
AuthorPosts