X Features Cars Demo Power Plants Demo State Parks Demo Site Showcase Docs Tutorials Add-ons Buy

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

$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

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 );