简体   繁体   中英

Re-init SearchWP Live Ajax Search

I'm using the SearchWP Live Ajax search in the navigation of a website in combination with BarbaJS. 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. I can't find a way in the documentation.

https://searchwp.com/extensions/live-search/

Based on this repo , this part of the code worked in my scenario.

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();
            });
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM