Skip to content

Documentation

Extensive Documentation for PowerPack & WooPack to help you with common questions and issues.

PowerPack

⌘K
  1. Home
  2. Docs
  3. PowerPack
  4. Modules
  5. Search Form
  6. How to integrate live AJAX based search in Search Form?

How to integrate live AJAX based search in Search Form?

SearchWP is a great plugin to add AJAX-based Live Search on the site. It can be integrated with PowerPack Search Form using pp_search_form_input_attrs hook.

Parameters:

$attrs – an ARRAY containing a key-value pair of all the attributes required for a Search Form.

$attrs = array(
         'placeholder'	=> $this->settings->placeholder,
         'class' 	=> array( 'pp-search-form__input' ),
         'type' 	=> 'search',
         'name' 	=> 's',
         'title' 	=> __( 'Search', 'bb-powerpack' ),
         'value'        => get_search_query(),
);

$settings – an OBJECT containing all the settings for the Search Form module instance.

SearchWP can be integrated into Search Form by setting data-swplive attribute to true as shown below.

Place the below code in your current theme’s functions.php file.

   add_filter( 'pp_search_form_input_attrs', 'my_function_modify_pp_search', 10, 2 );

   function my_function_modify_pp_search( $attrs, $settings ) {
       $attrs['data-swplive'] = 'true';
       return $attrs;
    }
🎃

SAVEBIG! Get up to 50% OFF this BFCM sale!  GRAB THE DEAL

×