[英]Re-init SearchWP Live Ajax Search
I'm using the SearchWP Live Ajax search in the navigation of a website in combination with BarbaJS.我结合 BarbaJS 在网站导航中使用 SearchWP Live Ajax 搜索。 After a page transition (without refresh) also the navigation is being re-added and that means that I need to re-init SearchWP Live Ajax search.
页面转换(不刷新)后,导航也被重新添加,这意味着我需要重新初始化 SearchWP Live Ajax 搜索。 I can't find a way in the documentation.
我在文档中找不到方法。
https://searchwp.com/extensions/live-search/ https://searchwp.com/extensions/live-search/
Based on this repo , this part of the code worked in my scenario.基于这个repo ,这部分代码在我的场景中有效。
if (typeof jQuery().searchwp_live_search == 'function') {
jQuery('input[data-swplive="true"]').searchwp_live_search();
// Gutenberg integration is based on a body class addition because we don't have the
// ability to manipulate the markup as we do with get_search_form().
if(typeof _SEARCHWP_LIVE_AJAX_SEARCH_BLOCKS !== 'undefined' && _SEARCHWP_LIVE_AJAX_SEARCH_BLOCKS) {
jQuery('input.wp-block-search__input').each(function() {
// Append data vars.
jQuery(this).attr('data-swpengine', _SEARCHWP_LIVE_AJAX_SEARCH_ENGINE);
jQuery(this).attr('data-swpconfig', _SEARCHWP_LIVE_AJAX_SEARCH_CONFIG);
// Init live search.
jQuery(this).searchwp_live_search();
});
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.