# Smart Search

## Hooks

### `wpe_smartsearch/extra_fields`

Filters the post fields before indexing.

```php
apply_filters( 'wpe_smartsearch/extra_fields', string $data, WP_Post $post )
```

#### Description

Use this filter to add or remove fields before an object is indexed.

#### Parameters

```php
$data array
```

Contains all of the data before indexing.

```php
$post WP_Post
```

The current post object being indexed.

#### Examples

Adding a custom field.

```php
add_filter(
    'wpe_smartsearch/extra_fields',
    function( array $data, WP_Post $post ) {
        $data['custom-field'] = 'custom field test';
        return $data;
    },
    10,
    2
);
```

Adding the post permalink.

```php
add_filter(
    'wpe_smartsearch/extra_fields',
    function( array $data, WP_Post $post ) {
        //sample value http://localhost:8000/hello-world
        $data['url'] = get_permalink($post);
        return $data;
    },
    10,
    2
);
```

Adding the post locale with a language plugin, i.e. `polylang`

```php
add_filter(
    'wpe_smartsearch/extra_fields',
    function( array $data, WP_Post $post ) {
        //sample valus EN | ES
        $data['locale'] = pll_get_post_language($post->ID);
        return $data;
    },
    10,
    2
);
```
