Download the PHP package danlapteacru/facetwp-builder without Composer
On this page you can find all versions of the php package danlapteacru/facetwp-builder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download danlapteacru/facetwp-builder
More information about danlapteacru/facetwp-builder
Files in danlapteacru/facetwp-builder
Package facetwp-builder
Short Description An Advanced FacetWP Builder for facets and templates.
License MIT
Homepage https://github.com/itinerisltd/facetwp-builder/
Informations about the package facetwp-builder
FacetWP Builder
Create, register, and reuse FacetWP plugin facets/templates using PHP, and keep them in your source code repository. To read more about registering FacetWP facets and templates via PHP, go here: facets documentation and templates documentation.
- Minimum Requirements
- Installation
- Adding/Removing FacetWP Facets and Templates with the Builder
- Composing Custom/3rd Party Addon Facets
- Hooks
- Examples
- Credits
- License
Minimum Requirements
- PHP v8.1
- WordPress v6.1
- FacetWP v4.0
Installation
If your project isn't using composer, you can require the autoload.php file.
Adding/Removing FacetWP Facets and Templates with the Builder
Table of Contents
| Facets | Templates |
|---|---|
| Autocomplete | Add a template |
| Checkbox | |
| Date Range | |
| Dropdown | |
| fSelect | |
| Hierarchy | |
| Number Range | |
| Pager | |
| Proximity | |
| Radio | |
| Reset | |
| Search | |
| Slider | |
| Sort | |
| Star Rating | |
| User Selections |
Facet Types
You can find a full reference of available facets on the official FacetWP documentation.
Autocomplete
Checkboxes
Date Range
Dropdown
fSelect
Hierarchy
Number Range
Pager
Proximity
Radio
Reset
Search
Slider
Sort
Star Rating
User Selections
Facet shortcut methods
Instead of passing all options as an array to the add method, you can chain setter methods on the returned FacetBuilder. All setters transform values automatically (booleans become 'yes'/'no' strings).
For custom/arbitrary attributes not in the list above, use setAttr(string $name, mixed $value) directly.
Managing facets
FacetsBuilder exposes the following methods for working with its facet collection:
Building and registering
Calling build() on the FacetsBuilder compiles the config and — by default — registers facets with FacetWP via the facetwp_facets WordPress filter.
Note: calling build() on the FacetBuilder returned by addSearch() / addCheckbox() / etc. builds only that single facet's config array and does not register anything with WordPress. Always call $builder->build() on the FacetsBuilder instance to register.
Templates
You can find a full reference of how to add a template with PHP on the official FacetWP documentation.
Add a template
Use addTemplate(string $name, array $args = []) to add a template. It returns a TemplateBuilder for further configuration.
Example using the array form:
Attention! The query key must contain a PHP code string. Use the setQuery() helper instead to pass a plain array and have it converted automatically.
Template shortcut methods
Example using chainable setters:
setPostType() and setPostsPerPage() are convenience helpers that update both query and query_obj in one call:
Default label
If setLabel() is not called and no label key is passed to addTemplate(), the label is auto-generated from the template name.
Default modes
If setModes() is not called and no modes key is passed, the following defaults are used:
Managing templates
TemplatesBuilder exposes the following methods for working with its template collection:
Building and registering templates
Composing Custom/3rd Party Addon Facets
Use addFacet(string $name, string $type, array $args = []) to add a facet with an arbitrary type string.
To use a type not in the built-in ALLOWED_FACET_TYPES constant, register it via the danlapteacru/facetwp-builder/allowed_facet_types filter hook.
Hooks
danlapteacru/facetwp-builder/allowed_facet_types
Filter the list of allowed facet types. Use this to add support for custom or 3rd-party addon types.
danlapteacru/facetwp-builder/facets
Filter the compiled facets array before it is returned by FacetsBuilder::build().
danlapteacru/facetwp-builder/facet_key
Filter the resolved facet type key before it is validated inside FacetsBuilder::__call(). Useful for aliasing method names to custom type strings.
danlapteacru/facetwp-builder/templates
Filter the compiled templates array before it is returned by TemplatesBuilder::build().
Examples
Table of Contents
| Examples |
|---|
| Add Facets |
| Add a custom facet |
| Add Template |
Add Facets
Add a custom facet
Add Template
Credits
FacetWP Builder is created and maintained by Dan Lapteacru.
Full list of contributors can be found here.
License
FacetWP Builder is released under the MIT License.