trendwerk / search
Basic extensions for searching in WordPress.
0.2.3
2018-10-16 18:22 UTC
Requires
- php: >=5.6
Requires (Dev)
- 10up/wp_mock: dev-master
- phpunit/phpunit: 5.7.*
- squizlabs/php_codesniffer: 2.*
README
Basic extensions for searching in WordPress.
Quick links: Install | Usage | Dimensions | Example
Note: This basic extension is not very scalable and meant for smaller databases. This package could get slow for complex searches. In that case, Elasticsearch would be a better solution.
Install
composer require trendwerk/search
Usage
Initialize
$search = new \Trendwerk\Search\Search(); $search->init();
This code should be run when bootstrapping your theme.
Dimensions
Currently this package supports metadata and terms as search dimensions. Dimensions can be added by using addDimension
:
$search->addDimension($dimension);
Meta
$metaDimension = new \Trendwerk\Search\Dimension\Meta($wpdb, [ 'key' => 'firstName', ]); $search->addDimension($metaDimension);
Available options for constructing an instance of Meta
:
Terms
$search->addDimension(new \Trendwerk\Search\Dimension\Term($wpdb, [ 'taxonomy' => 'taxonomyName', ]));
Available options for constructing an instance of Term
:
Example
use Trendwerk\Search\Dimension\Meta; use Trendwerk\Search\Dimension\Term; use Trendwerk\Search\Search; $search = new Search(); $search->init(); $search->addDimension(new Meta($wpdb, [ 'compare' => 'LIKE', 'key' => 'lastNames%', ])); $search->addDimension(new Meta($wpdb, [ 'key' => 'firstName', ])); $search->addDimension(new Term($wpdb, [ 'taxonomy' => 'category', ]));