Forums › Forums › Search & Filter Pro › Problem with ajax results missing audio player
Tagged: ACF and SF
- This topic has 11 replies, 4 voices, and was last updated 8 years, 3 months ago by
Anonymous.
-
Ross Moderator(Private) April 2, 2015 at 6:49 pm #14444
Hi Adrian
What is happening is, when the page loads, your theme is doing all kinds of stuff like loading the scripts for your audio player and attaching them to the page.
Then, once you use ajax, these audio player are removed, and new results are brought in. However this scenario is different because your theme doesn’t run the scripts it needs to setup those audio players.
Take a look at the first question here:
http://www.designsandcode.com/wordpress-plugins/search-filter-pro/faqs/Basically you need to run the same scripts (for setting up audio players) that your theme runs when ajax has finished loading – your theme developer may know of some functions that could do this.
Thanks
Anonymous(Private) April 2, 2015 at 7:31 pm #14457Hi Ross,
Thanks for the quick reply. The FAQ helped a lot, and I just added the following into my .js file and it works great:
$(“.searchandfilter”).on(“sf:ajaxfinish”,function(){
$(‘video,audio’).mediaelementplayer();
});Users should not need to refresh the page, but if they do, the title of the page still changes to “Blog | Site Title”
Any further suggestions?
Ross Moderator(Private) April 2, 2015 at 8:22 pm #14462check out this thread 😉
https://support.searchandfilter.com/forums/topic/change-page-title-for-search-results/
Anonymous(Private) April 2, 2015 at 8:43 pm #14464Thanks Ross – spot on. You are a patient man.
Here is the code I used in functions.php:
add_filter('wpseo_title','search_meta_title'); function search_meta_title($data){ global $sf_form_data; if($sf_form_data->form_id()==1272) { return 'Sermons'; } else { return $data; } }Anonymous(Private) August 22, 2017 at 8:27 am #127088Hello, I have the same problem with my audio player that changes shape and color once the rescheerche display. I see you say you have to put in the js:
$ ( “Searchandfilter.”) One (“sf: ajaxfinish.”, Function () {
$ (‘Video, audio’) mediaelementplayer ().
});
But where exactly? This is serach-filter-build.js?
cordiallyAnonymous(Private) August 22, 2017 at 9:41 am #127103I put it in a separate .js file that is registered using wp_register_script and queued using wp_enqueue_script within functions.php in the usual way.
Note your code is wrong in a number of ways. It should be:
$(".searchandfilter").on("sf:ajaxfinish",function(){ $('video,audio').mediaelementplayer(); });Trevor(Private) August 22, 2017 at 11:13 am #127111If you are placing that code inline on the page, it would become like this:
<script>(function ( $ ) { "use strict"; $(document).on("sf:ajaxfinish", ".searchandfilter", function(){ console.log("ajax complete"); $('video,audio').mediaelementplayer(); }); }(jQuery));</script>Anonymous(Private) August 22, 2017 at 11:20 am #127113It seems very daunting to start with, but there are plenty of tutorials on how to correctly enqueue script files (.js) E.g. https://premium.wpmudev.org/blog/adding-scripts-and-styles-wordpress-enqueueing/
Add your code into a new .js file (E.g. website-scripts.js in the example) that is in your theme folder.
-
AuthorPosts