Skip to content

Instantly share code, notes, and snippets.

@mgibbs189
Created December 21, 2015 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgibbs189/fba666d9f15b361fa5b2 to your computer and use it in GitHub Desktop.
Save mgibbs189/fba666d9f15b361fa5b2 to your computer and use it in GitHub Desktop.
FacetWP - modify date_range facet to find posts on a certain day
<?php
function fwp_match_exact_day( $return, $params ) {
$facet = $params['facet'];
$values = $params['selected_values'];
if ( 'YOUR_FACET_NAME' == $facet['name'] ) {
global $wpdb;
$where = '';
if ( '' != $values[0] ) {
$where .= " AND LEFT(facet_value, 10) = '{$values[0]}'";
}
$sql = "
SELECT DISTINCT post_id FROM {$wpdb->prefix}facetwp_index
WHERE facet_name = '{$facet['name']}' $where";
return $wpdb->get_col( $sql );
}
return $return;
}
add_filter( 'facetwp_facet_filter_posts', 'fwp_match_exact_day', 10, 2 );
@anybodesign
Copy link

Hi, I'm interested in this gist but I'm not sure to fully understand how it works…
I'm trying to filter posts which custom date field is older than today, don't know if I can customize this code to achieve that :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment