• Resolved grayham

    (@grayham)


    Hello,

    I am looking to use the wp-events-plugin to display past events from a given category for this year.

    I have attempted to form a shortcode to accomplish this by using the parameters described in the shortcode documentation.

    [events_list year="2015" scope="past" limit="0" category="10"]#_EVENTLINK<br /> #_EVENTDATES #_LOCATIONTOWN<br /><br />[/events_list]

    Unfortunately the results returned show all the events from 2015 (including future events) rather than just the past events.

    I would like to ask if anyone knows a way to accomplish this either using shortcodes or another method?

    Many thanks in advance for your time.

    https://www.ads-software.com/plugins/events-manager/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support angelo_nwl

    (@angelo_nwl)

    hi,

    you can just try this shortcode

    [events_list scope="future" limit="10" pagination=1 category="10"]
     #_EVENTLINK<br /> #_EVENTDATES #_LOCATIONTOWN<br /><br />
    [/events_list]
    Thread Starter grayham

    (@grayham)

    Hi Angelo,

    Sorry I am afraid that does not work for the purpose I am looking for.

    The code above gives me a paginated list of future events.

    I am looking for a list of past events within a given category within 2015.

    Plugin Support angelo_nwl

    (@angelo_nwl)

    I see now, you’ve wanted to list past events within 2015 only filtered by category but at the moment you can only use the year search attribute and/or using scope search attribute you can use date ranges (eg. 2015-01-01,2015-01-23) or create new scope using this tutorial – https://wp-events-plugin.com/tutorials/create-your-own-event-scope/

    As for where to paste this : https://wp-events-plugin.com/tutorials/how-to-safely-add-php-code-to-wordpress/

    Thread Starter grayham

    (@grayham)

    Hi Angelo,

    Sorry for my delay in reply. I managed to get this working with your instructions. Thank you!

    For reference; the code I used was…

    <?php
    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']=='this-year' ){
    		$start_date = date('Y-m-d',strtotime("First day of January", current_time('timestamp')));
    		$end_date = date('Y-m-d',current_time('timestamp'));
    		$conditions['scope'] = " (event_start_date BETWEEN CAST('$start_date' AS DATE) AND CAST('$end_date' AS DATE)) OR (event_end_date BETWEEN CAST('$end_date' AS DATE) AND CAST('$start_date' AS DATE))";
    	}
    	return $conditions;
    }
    
    add_filter( 'em_get_scopes','my_em_scopes',1,1);
    function my_em_scopes($scopes){
    	$my_scopes = array(
    		'this-year' => 'Events this year'
    	);
    	return $scopes + $my_scopes;
    }
    ?>

    i do exactly search for a result of that question.
    i can set this in functions.php of my childtheme – and then?
    how is the shortcode for your instance?

    ok i got it the new scope in your code here is “this-year”
    and means past events but only this year –
    great – thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Show past events for a given year’ is closed to new replies.