→ facetwp_facet_filter_posts

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)

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

Returns

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

Usage

<?php
function facet_availability_logic( $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;
}

add_filter( 'facetwp_facet_filter_posts', 'facet_availability_logic', 10, 2 );