• Hi, thanks again for a wonderful plugin.

    I posted this over a year ago with no solution.

    {is_newpost}*NEW*{/is_newpost} is not working following upgrade with the following code, can anyone assist?

    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 H:i:s',strtotime("-2 days", current_time('timestamp')));
                    $conditions['scope'] = " ( event_date_modified >= '$start_date') OR ( 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;
    }
    
    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_date_created) >= strtotime("-3 days", current_time('timestamp'))){
                $replacement = preg_replace("/\{\/?$condition\}/", '', $match);
            }else{
                $replacement = '';
            }
        }
        return $replacement;
    }

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Here’s a tutorial on how to create a conditional placeholder: https://wp-events-plugin.com/documentation/tutorials/creating-conditional-placeholders-for-events/

    To create a {is_newpost} conditional placeholder which will be true when the event has been created within the last three days you could use the following code snippet:

    add_action('em_event_output_show_condition', 'my_em_new_event_output_show_condition', 1, 4);
    function my_em_new_event_output_show_condition($show, $condition, $full_match, $EM_Event){
    if( "is_newpost" == $condition ){
    $show = strtotime($EM_Event->event_date_created) >= strtotime("-3 days", current_time('timestamp')) ? true : false;
    }
    return $show;
    }
    Thread Starter gleanreport

    (@gleanreport)

    Thanks for providing this code snippet. I have tried using the code but it does not bring up the *NEW* label before the text for events created within the last three days.

    Here’s a corrected version of the code snippet:

    add_action('em_event_output_show_condition', 'my_em_new_event_output_show_condition', 1, 4);
    function my_em_new_event_output_show_condition($show, $condition, $full_match, $EM_Event){
    if( "is_newpost" == $condition ){
    $postdate = get_post_datetime($EM_Event->post_id)->format('Y-m-d');
    $threedaysago = date('Y-m-d', strtotime('-3 days', current_time('timestamp')));
    $show = strtotime($postdate) >= strtotime($threedaysago) ? true : false;
    }
    return $show;
    }
    Thread Starter gleanreport

    (@gleanreport)

    That appears to be working! Thank you so much. I’ll test it over the next few days and confirm.

    Thread Starter gleanreport

    (@gleanreport)

    Confirmed that it is working thank you so much! Is there a way to add posts that are modified in the past 3 days as well as those that have been created?

    Here’s the new version that will  include posts that were modified in the past 3 days as well as those that were created in the past 3 days :

    add_action('em_event_output_show_condition', 'my_em_new_event_output_show_condition', 1, 4);
    function my_em_new_event_output_show_condition($show, $condition, $full_match, $EM_Event){
    if( "is_newpost" == $condition ){
    global $wpdb;
    $row = $wpdb->get_row($wpdb->prepare("SELECT event_date_modified FROM ".EM_EVENTS_TABLE.' WHERE event_id=%s', $EM_Event->event_id));
    $event_date_modified = $row ? $row->event_date_modified : null;
    $postdate = get_post_datetime($EM_Event->post_id)->format('Y-m-d');
    $threedaysago = date('Y-m-d', strtotime('-3 days', current_time('timestamp')));
    $show = (strtotime($postdate) >= strtotime($threedaysago) || ($event_date_modified !== null && strtotime($event_date_modified) >= strtotime($threedaysago))) ? true : false;
    }
    return $show;
    }
Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Conditional placeholder not working’ is closed to new replies.