I’ve made a few changes to your no_notes code and tested it to be sure that it works.
function em_event_output_condition_filter($replacement, $condition, $match, $EM_Event) {
// Checks for has_notes conditional
if (is_object($EM_Event) && preg_match('/^has_(notes)$/', $condition, $matches)) {
if (isset($EM_Event->$matches[1]) && !empty($EM_Event->$matches[1])) {
$replacement = preg_replace("/\{\/?$condition\}/", '', $match);
} else {
$replacement = '';
}
}
// Checks for no_notes conditional
if (is_object($EM_Event) && preg_match('/^no_(notes)$/', $condition, $matches)) {
if (!isset($EM_Event->$matches[1]) || empty($EM_Event->$matches[1])) {
$replacement = preg_replace("/\{\/?$condition\}/", '', $match);
} else {
$replacement = '';
}
}
return $replacement;
}
add_filter('em_event_output_condition', 'em_event_output_condition_filter', 1, 4);
This is an example of how it could be used:
{has_notes} This text will show up if notes have been filled out: #_EVENTNOTES {/has_notes}
{no_notes} This text will only show up if notes is empty. {/no_notes}
Thread Starter
danbru
(@danbru)
Thank you for your time! That works!
Need this for locations too, so I changed all the “event”‘s to “location” and it’s not working for locations. Could you help there too?
/* ========== EVENTS MANAGER – CUSTOM CODE ========== */
function em_event_output_condition_filter($replacement, $condition, $match, $EM_Event) {
// Checks for Event {has_notes} conditional
if (is_object($EM_Event) && preg_match('/^has_(notes)$/', $condition, $matches)) {
if (isset($EM_Event->$matches[1]) && !empty($EM_Event->$matches[1])) {
$replacement = preg_replace("/\{\/?$condition\}/", '', $match);
} else {
$replacement = '';
}
}
// Checks for Event {no_notes} conditional
if (is_object($EM_Event) && preg_match('/^no_(notes)$/', $condition, $matches)) {
if (!isset($EM_Event->$matches[1]) || empty($EM_Event->$matches[1])) {
$replacement = preg_replace("/\{\/?$condition\}/", '', $match);
} else {
$replacement = '';
}
}
return $replacement;
}
add_filter('em_event_output_condition', 'em_event_output_condition_filter', 1, 4);
function em_location_output_condition_filter($replacement, $condition, $match, $EM_Location) {
// Checks for Location {has_notes} conditional
if (is_object($EM_Location) && preg_match('/^has_(notes)$/', $condition, $matches)) {
if (isset($EM_Location->$matches[1]) && !empty($EM_Location->$matches[1])) {
$replacement = preg_replace("/\{\/?$condition\}/", '', $match);
} else {
$replacement = '';
}
}
// Checks for Location {no_notes} conditional
if (is_object($EM_Location) && preg_match('/^no_(notes)$/', $condition, $matches)) {
if (!isset($EM_Location->$matches[1]) || empty($EM_Location->$matches[1])) {
$replacement = preg_replace("/\{\/?$condition\}/", '', $match);
} else {
$replacement = '';
}
}
return $replacement;
}
add_filter('em_location_output_condition', 'em_location_output_condition_filter', 1, 4);
No problem. This can be made to work for locations as well, but the $EM_Location object doesn’t have a ‘notes’ property. Instead it’s called ‘post_content’, yet represents the same field. Due to the naming differences you either need to change the conditional to be {has_post_content} {/has_post_content} {no_post_content} {/no_post_content}, or keep the same naming convention (for consistency sake between events and locations) and hardcode the post_content property into the conditional function.
I’ve added the functioning (and tested) code for {has_notes} and {no_notes} for locations below:
function em_location_output_condition_filter($replacement, $condition, $match, $EM_Location) {
// Checks for has_notes conditional
if (is_object($EM_Location) && preg_match('/^has_(notes)$/', $condition, $matches)) {
if (isset($EM_Location->post_content) && !empty($EM_Location->post_content)) {
$replacement = preg_replace("/\{\/?$condition\}/", '', $match);
} else {
$replacement = '';
}
}
// Checks for no_notes conditional
if (is_object($EM_Location) && preg_match('/^no_(notes)$/', $condition, $matches)) {
if (!isset($EM_Location->post_content) || empty($EM_Location->post_content)) {
$replacement = preg_replace("/\{\/?$condition\}/", '', $match);
} else {
$replacement = '';
}
}
return $replacement;
}
add_filter('em_location_output_condition', 'em_location_output_condition_filter', 1, 4);
Thread Starter
danbru
(@danbru)
Thanks!
I really appreciate your help!