Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Compare two custom fields before displaying them
- This topic has 3 replies, 2 voices, and was last updated 8 months, 2 weeks ago by
Ernest Marcinko.
-
AuthorPosts
-
September 15, 2025 at 5:12 pm #55431
Yans
ParticipantHi,
I am using ASP to list and search events that come from the EventOn plugin.Each event has start date and end date.
I configured ASP to show the start and end dates in the search results and using the following code (based on code you sent me) to convert timestamp to normal date:
/** * Converting event start and end dates from UNIX timestamp to human date */ add_filter('asp_cpt_advanced_field_value', function($value, $field_name){ if ( $field_name == 'evcal_srow' ) { return date_i18n( "F j, Y", $value); } elseif ( $field_name == 'evcal_erow' ) { return date_i18n( "F j, Y", $value); } else { return $value; } }, 10,2);The problem is that some events have the same start and end date. With the current configuration, ASP displays both start and end dates.
Is there a way to compare evcal_srow and evcal_erow and if they are the same, not display evcal_erow (the end date)?
Thanks!
September 15, 2025 at 5:22 pm #55432Ernest Marcinko
KeymasterHi,
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):
September 16, 2025 at 7:53 am #55446Yans
ParticipantHi,
Thank you very much for the quick reply!
The code worked (had to change “10,2” to “10,3”).
This ticket can be closed.
September 16, 2025 at 2:00 pm #55455Ernest Marcinko
KeymasterYou cannot access this content.
-
AuthorPosts
- You must be logged in to reply to this topic.