thinib
Forum Replies Created
-
It worked fine previously – I think something has changed in the upgrades with Events Manager
Trying again:
add_action('em_event_output_condition', 'my_em_styles_event_output_condition', 1, 4); function my_em_styles_event_output_condition($replacement, $condition, $match, $EM_Event){ if( is_object($EM_Event) && preg_match('/^is_newpost$/',$condition, $matches) ){ if( strtotime($EM_Event->event_modified) >= strtotime("-3 days", current_time('timestamp'))){ $replacement = preg_replace("/\{\/?$condition\}/", '', $match); }else{ $replacement = ''; } } return $replacement; }
Sorry, my mistake. I think the top part of the code is for a scope function that does work. It’s this part that isn’t working:
`add_action(’em_event_output_condition’, ‘my_em_styles_event_output_condition’, 1, 4);
function my_em_styles_event_output_condition($replacement, $condition, $match, $EM_Event){
if( is_object($EM_Event) && preg_match(‘/^is_newpost$/’,$condition, $matches) ){
if( strtotime($EM_Event->event_modified) >= strtotime(“-3 days”, current_time(‘timestamp’))){
$replacement = preg_replace(“/\{\/?$condition\}/”, ”, $match);
}else{
$replacement = ”;
}
}
return $replacement;
}Hi Caimin,
I’m not sure how to display the output from that feed (the url is gleanreport.com), but when I put {is_newpost}*NEW*{/is_newpost} in Default event list format I used to get a display for new posts, now I’m getting nothing.
Sorry I’ll try to put the code in backticks now:
add_filter( 'em_get_scopes','my_em_scopes',1,1); function my_em_scopes($scopes){ $my_scopes = array( 'newposts' => 'New Posts' ); return $scopes + $my_scopes; } add_action('em_event_output_condition', 'my_em_styles_event_output_condition', 1, 4); function my_em_styles_event_output_condition($replacement, $condition, $match, $EM_Event){ if( is_object($EM_Event) && preg_match('/^is_newpost$/',$condition, $matches) ){ if( strtotime($EM_Event->event_modified) >= strtotime("-3 days", current_time('timestamp'))){ $replacement = preg_replace("/\{\/?$condition\}/", '', $match); }else{ $replacement = ''; } } return $replacement; }
Duh, that’s because the scope works with event_date_created, but the conditional placeholder using $EM_Event->event_date_created does not. Here is my code for the scope which works:
add_filter( 'em_events_build_sql_conditions', 'my_em_scope_conditions',1,2); function my_em_scope_conditions($conditions, $args){ if( !empty($args['scope']) && $args['scope']=='newposts' ){ $start_date = date('Y-m-d',strtotime("-2 days", current_time('timestamp'))); $conditions['scope'] = " ( event_date_created >= '$start_date') "; } return $conditions; } add_filter( 'em_get_scopes','my_em_scopes',1,1); function my_em_scopes($scopes){ $my_scopes = array( 'newposts' => 'New Posts' ); return $scopes + $my_scopes; }
But the code below only works with $EM_Event->event_modified, not $EM_Event->event_date_created
add_action('em_event_output_condition', 'my_em_styles_event_output_condition', 1, 4); function my_em_styles_event_output_condition($replacement, $condition, $match, $EM_Event){ if( is_object($EM_Event) && preg_match('/^is_newpost$/',$condition, $matches) ){ if( strtotime($EM_Event->event_modified) >= strtotime("-2 days", current_time('timestamp'))){ $replacement = preg_replace("/\{\/?$condition\}/", '', $match); }else{ $replacement = ''; } } return $replacement; }
It seems that $EM_Event->event_date_created works in the code when I use shortcode, such as [events_list scope=’newposts’], but not when I use a conditional placeholder, such as {is_newpost}*NEW*{/is_newpost}. However $EM_Event->date_modified works for both. Can’t work out why! Any ideas?
I have tried that, no good. I’m currently using $EM_Event->date_modified which gives me something close, but includes events that have been modified recently, not just created.
Forum: Plugins
In reply to: [WP FullCalendar] Integration of calendar with event manager search formAngelo,
I’m using Events Manager with WP Full Calendar, and the EM search form is not working (it works fine when WP Full Calendar is deactivated).
Are you saying I can’t make it work without creating some custom code?
Angelo,
Is there anyway to extract the date the event is created for each event? I think I can get this code to work if I know how to do that.
I’ve tried various ways, Caiman suggested $EM_Event->created, but this doesn’t work. I’ve also tried: $EM_Event->event_date_created, $EM_Event->date_created etc
Any suggestions?
Thanks Angelo – that was really helpful!
I’ve changed the scope to use that php condition too, so I feel like I’m very close now, but the conditional placeholder is still not quite working. So far I have this, can you see if I’ve made some glaring error:
add_action('em_event_output_condition', 'my_em_styles_event_output_condition', 1, 4); function my_em_styles_event_output_condition($replacement, $condition, $match, $EM_Event){ if( is_object($EM_Event) && preg_match('/^is_newpost$/',$condition, $matches) ){ $start_date = date('Y-m-d',strtotime("-3 days", current_time('timestamp'))); if (event_date_created > '$start_date'){ $replacement = preg_replace("/\{\/?$condition\}/", '', $match); }else{ $replacement = ''; } } return $replacement; }
For example, I’ve tried to create the following, but wondering if there are other snippets of similar coding I could look at as this doesn’t work?
add_action('em_event_output_condition', 'my_em_styles_event_output_condition', 1, 4); function my_em_styles_event_output_condition($replacement, $condition, $match, $EM_Event){ if( is_object($EM_Event) && preg_match('//^is_newposts$//',$condition, $matches) ){ if( in_array('scope'=>'newposts') ){ $replacement = preg_replace("/\{\/?$condition\}/", '', $match); }else{ $replacement = ''; } } return $replacement; }
One more question – now that I have this working as a custom scope, can I use it to create a conditional placeholder?
I got it! I used event_date_created instead of event_creation_date and it now works.
Thanks for all your help.
Thanks Angelo,
I’m still working on this.
Can you tell me, would this code work for event_creation_date or event_modification_date rather than event_start_date or event_end_date?