Created
December 21, 2015 18:23
-
-
Save mgibbs189/fba666d9f15b361fa5b2 to your computer and use it in GitHub Desktop.
FacetWP - modify date_range facet to find posts on a certain day
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 :)