Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Compare two custom fields before displaying them › Reply To: Compare two custom fields before displaying them
September 15, 2025 at 5:22 pm
#55432
Keymaster
Hi,
Surely!
The way I would try to do this is to check the start date and compare when the field name is “ecval_erow” and then return and empty string “”, that basically unsets the value and the field becomes empty:
add_filter('asp_cpt_advanced_field_value', function($value, $field_name, $result){
if ( $field_name === 'evcal_srow' ) {
return date_i18n( "F j, Y", $value);
} elseif ( $field_name === 'evcal_erow' ) {
$start_date = get_post_meta($result->id, 'evcal_srow', true);
if ( $start_date == $value ) {
return '';
}
return date_i18n( "F j, Y", $value);
} else {
return $value;
}
}, 10,2);
I’m not sure this is the final code, you may have to test it first.
Then if you use the conditional square brackets to wrap the field, then you can hide the whole part with text and everything when the “evcal_erow” is returned empty (when it’s the same as the start date):