Forums › Forums › Search & Filter Pro › How to reload S&F properly after ajax page refreshes v.2.0.1
- This topic has 5 replies, 2 voices, and was last updated 9 years, 1 month ago by Anonymous.
-
Anonymous(Private) September 24, 2015 at 2:14 pm #25714
Hi,
I loaded the new version yesterday but have had to revert to 1.4.3 because some of my custom functions are not working correctly with 2.0.1
I am currently using this code in 1.4.3 to recall the form ID after my ajax page refresh…
if (class_exists('Search_Filter')){ global $sf_form_data; wp_localize_script('djax_init', 'SF_LDATA', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'home_url' => (home_url('/')), 'sfid' => $sf_form_data->get_active_form_id() )); }
BUT in 2.0.1 it does not work and I can’t figure out what I need to change apart from the global var ($searchandfilter). I get an error regarding the get_active_form_id() so obviously something has changed in the new version.
Also the code which names the search page is incorrect too….
/***SEARCH & FILTER PRO FUNCTIONS***/ if (class_exists('Search_Filter')){ //wp_enqueue_script( 'search-filter-plugin-build' ); //wp_enqueue_script( 'search-filter-chosen-script' ); // Search Page Title - Yoast SEO friendly :-) function search_meta_title($data){ global $sf_form_data; if ( $sf_form_data->is_valid_form() ) { return 'Search Results'; } else { return $data; } } add_filter('wpseo_title','search_meta_title'); add_filter('wp_title','search_meta_title');
Can anyone help me update my functions?
Ross Moderator(Private) September 24, 2015 at 3:04 pm #25724Good catch
I think renaming the global is enough most of your code above, however I’ve mistakenly and stupidly removed
get_active_form_id()
when refactoring – I’ll add it back in this afternoon or some equivalent and let you know.Thanks
Ross Moderator(Private) September 24, 2015 at 10:45 pm #25798Hi Sarah
Sending over a mail now…
Looks like I’ve messed with these two functions a bit, I think I just didn’t think about this use case properly.
So now in the latest version you should be able to use this function instead:
$searchandfilter->active_sfid();
So, active SFID returns the ID of the active search form. You can use this function in both uses cases above because an ID of
0
means its not active.So in your first code snippet instead of
$sf_form_data->get_active_form_id()
use:
$searchandfilter->active_sfid();
And in your second code snippet, instead of:
if ( $sf_form_data->is_valid_form() ) { return 'Search Results'; } else { return $data; }
It should be changed to:
if ( $searchandfilter->active_sfid() ) { return 'Search Results'; } else { return $data; }
Thanks!
-
AuthorPosts