Overview

This filter lets you override the filtering logic for specific facet(s).

By default, FacetWP uses its own index table to determine matching posts. With this filter, you could theoretically hook into custom database tables (e.g. for doing real-time booking availability) or 3rd party services.

Parameters

  • $return | mixed | FALSE (default), or an array of post IDs
  • $params | An associative array of parameters (see below)

How to use custom PHP code?

PHP code can be added to your (child) theme's functions.php file. Alternatively, you can use the Custom Hooks add-on, or a code snippets plugin. More info

$params = [ 'facet' => [ 'label' => 'My facet', 'name' => 'my_facet', 'type' => 'checkboxes', 'source' => 'cf/the_field_name', // ... other facet meta ], 'selected_values' => [] ];

Returns

An array of post IDs, or FALSE to use FacetWP’s default filtering logic

Usage

How to use custom PHP code?

PHP code can be added to your (child) theme's functions.php file. Alternatively, you can use the Custom Hooks add-on, or a code snippets plugin. More info

add_filter( 'facetwp_facet_filter_posts', function( $return, $params ) { $selected_values = $params['selected_values']; if ( 'availability' == $params['facet']['name'] ) { $start_date = $selected_values[0]; $end_date = $selected_values[1]; // get post IDs of available rooms between these dates $post_ids = fake_get_available_rooms( $start_date, $end_date ); return $post_ids; } return $return; }, 10, 2 );

More examples

See also