Hi,
I have three fields:
Year of Birth - Stores the year of birth
Year - Use to search the years of birth
Range - to set a range for the search. For example if Year equals 1882 and the range is set to +/- 1 then it should give the result 1881, 1882 and 1883
I am using the attached code but it returns no results. Can anyone help identify the problem?
Thanks!
I suggest turning on WordPress debugging and putting in error_log statements to see what the values are at various points in the code.
hey,
I tried that and I don't see any bugs.
It's not necessarily a bug you're looking for, it's more about whether the values are correct at every point during the process. I don't even recall what the code is and the link seems to be dead.
This was the code
function custom_filter_entries($where, $args) {
error_log("Initial WHERE clause: " . $where);
$view_id = 55;
$year_field_id = 175;
$range_field_id = 178;
if ($args['display']->ID == $view_id && $args['where_opt'] == $year_field_id) {
$selected_range = isset($_GET['range']) ? sanitize_text_field(urldecode($_GET['range'])) : '';
error_log("Selected Range: " . $selected_range);
if (!empty($selected_range)) {
$central_year = intval($_GET['yearofbirth']);
$range_years = array();
if ($selected_range == "-/+ 1yrs") {
$range_years = array($central_year - 1, $central_year, $central_year + 1);
} elseif ($selected_range == "-/+ 2yrs") {
for ($i = -2; $i <= 2; $i++) {
$range_years[] = $central_year + $i;
}
}
$conditions = array();
foreach ($range_years as $year) {
$conditions[] = "meta_value LIKE '%" . esc_sql($year) . "%'";
}
$where = "(" . implode(" OR ", $conditions) . ")";
error_log("Modified WHERE clause: " . $where);
}
}
return $where;
}
add_filter('frm_where_filter', 'custom_filter_entries', 10, 2);
Please login or Register to submit your answer