PHPackages                             amostajo/wordpress-search-typeahead - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. amostajo/wordpress-search-typeahead

ActiveLibrary

amostajo/wordpress-search-typeahead
===================================

Wordpress Search Typeahead Add-on for Wordpress Development Templates.

v1.0.0(10y ago)081MITPHPPHP &gt;=5.4.0

Since Nov 20Pushed 10y ago1 watchersCompare

[ Source](https://github.com/amostajo/wordpress-search-typeahead)[ Packagist](https://packagist.org/packages/amostajo/wordpress-search-typeahead)[ RSS](/packages/amostajo-wordpress-search-typeahead/feed)WikiDiscussions v1.0 Synced 2mo ago

READMEChangelog (1)Dependencies (1)Versions (3)Used By (0)

Wordpress Search Typeahead ADD-ON
=================================

[](#wordpress-search-typeahead-add-on)

[![Latest Stable Version](https://camo.githubusercontent.com/3e128da0218b713618586efbba9cdc6c6fa6cd6e5ff49894ec1597e5a388cca7/68747470733a2f2f706f7365722e707567782e6f72672f616d6f7374616a6f2f776f726470726573732d7365617263682d7479706561686561642f762f737461626c65)](https://packagist.org/packages/amostajo/wordpress-search-typeahead)[![Total Downloads](https://camo.githubusercontent.com/35fcfa2b9ef0f99b34966b50037d02efe207a75c7bd4f7a9487c5fa11653aa31/68747470733a2f2f706f7365722e707567782e6f72672f616d6f7374616a6f2f776f726470726573732d7365617263682d7479706561686561642f646f776e6c6f616473)](https://packagist.org/packages/amostajo/wordpress-search-typeahead)[![License](https://camo.githubusercontent.com/4533aaebadae9e1ae25be8e577fc19372ebc62584209592b3e5509b48e16778b/68747470733a2f2f706f7365722e707567782e6f72672f616d6f7374616a6f2f776f726470726573732d7365617263682d7479706561686561642f6c6963656e7365)](https://packagist.org/packages/amostajo/wordpress-search-typeahead)

Add-on package for [Wordpress Plugin Template](https://github.com/amostajo/wordpress-plugin) and [Wordpress Theme Template](https://github.com/amostajo/wordpress-theme) exclusively.

**Typeahead** integrates Twitter's typeahead with wordpress, providing a flexible way to add customization and functionality for post searches.

- [Installation](#installation)
    - [Configure in Template](#configure-in-template)
- [Usage](#usage)
    - [On Templates](#on-templates)
        - [Changing filters](#changing-filters)
    - [Hooks](#hooks)
    - [Customization](#customization)
- [Coding Guidelines](#coding-guidelines)
- [Copyright](#copyright)

Installation
------------

[](#installation)

This package requires [Composer](https://getcomposer.org/).

Add it in your `composer.json` file located on your template's root folder:

```
"amostajo/wordpress-search-typeahead": "1.0.*"
```

Then run

```
composer install
```

or

```
composer update
```

to download package and dependencies.

### Configure in Template

[](#configure-in-template)

Add the following string line in your `addons` array option located at your template's config file.

```
    'Amostajo\Wordpress\TypeaheadAddon\Typeahead',
```

This should be added to:

- `config\plugin.php` on Wordpress Plugin Template
- `config\theme.php` on Wordpress Theme Template

Usage
-----

[](#usage)

### On Templates

[](#on-templates)

Call `typeahead_search()` function within your template, like this:

```

```

#### Changing filters

[](#changing-filters)

Typeahead uses *WP\_Query* to retrieve posts, you can modify the results of the search like this:

```

     'product' ] ) ?>

```

### Hooks

[](#hooks)

**FILTER**: `addon_typeahead_query`Filters the arguments passed to *WP\_Query* by default.

```
add_filter( 'addon_typeahead_query', 'filter_query' );

function filter_query ($args) {
    // Array modifications
    $args['post_type'] = 'product';
    $args['posts_per_page'] = 10;

    // Array is expected in return
    return $args;
}
```

**FILTER**: `addon_typeahead_post`Filters each *WP\_Post* object returned by *WP\_Query*. If this is not modified, the add-on will convert the post result into a Post model (located in this package).

```
add_filter( 'addon_typeahead_post', 'filter_post' );

function filter_post ($post) {

    // Transformation of post into custom model
    $model = new MyModels\CustomPost();

    // Array is expected in return
    return $model->from_post( $post )->to_array();
}
```

**FILTER**: `addon_typeahead_data`Filters final results. Receives the data as array and the search arguments (those used for WP\_Query).

```
add_filter( 'addon_typeahead_data', 'filter_data' );

function filter_data ($data, $args) {

    // Adding custom records in results
    if ( $args['post_type'] != 'product' ) {
        // Adding extra product
        $data[] = MyProduct::find(999)->to_array();
    }

    // Array is expected in return
    return $data;
}
```

### Customization

[](#customization)

All views located at the `views` folder can be customized in your theme. Copy and paste them in your theme (same as you would do for plugin views) and modify them.

Things to consider:

```
