Scott Fichter
Scott Fichter

Reputation: 51

Wordpress Plugin The Events Calendar - Listing All Events For One Year

I've been struggling (I'm a newb) on how to have The Events Calendar print a list of all events within a specified year. I researched this need heavily online and I'm surprised that there's limited info on the subject. The list is simple really. It just needs to be a linked title that sends the user to the actual event page.

My approach was to create a custom [shortcode] in functions.php so I could place the list on any WordPress page or post that I need.

The custom shortcode PHP is the following.

add_shortcode('yearList', 'yearList');
function sayHello()
{
echo '<h1>Hello World</h1>';
}

I added this to the functions.php file within the Genesis child theme root. The text echoed fine so that part is good to go.

After researching the forums at Modern Tribe I came across a useful page that reviews the tribe_get_events function. Here's the page for those wondering.

Any way, the code in this page gets me close so I know I'm on the right track. The PHP that I'm using within the created shortcode function is the following.

// Setting up custom function called yearList
add_shortcode('yearList', 'yearList');
function yearList()
{

// Ensure the global $post variable is in scope
global $post;

// Retrieve all events desired year. Only eight printed out of 80.
$events = tribe_get_events( array(
'eventDisplay' => 'custom',
'start_date'   => '2014-01-01 00:01',
'end_date'     => '2014-12-31 23:59'
) );

// Loop through the events: set up each one as
// the current post then use template tags to
// display the title and content
foreach ( $events as $post ) {
setup_postdata( $post );

// prints the title for each event.
echo '<br><br>'; 
//  WRONG WRONG - This is below is what's throwing me. 
echo '<a href="<?php echo tribe_get_event_link() ?>" title="<?php the_title() ?>"></a>';
//the_title();
// echo tribe_get_start_date();  This shows the start date and time after the event title I slept this for now.

}
}

I have two questions.

  1. Why would the loop only show nine titles when I have over 80 stamped for 2014?
  2. How can make each line be a link to The Calendar Events actual event page? I've tried to employ this with no luck.

Thanks for any help on this.

Upvotes: 2

Views: 2569

Answers (1)

cpilko
cpilko

Reputation: 11852

For your first problem, try adding posts_per_page => -1 inside your $events = tribe_get_events( array( ... ); statement. The default limit must be set to 9 posts somewhere. If that doesn't work, try replacing -1 with a large number.

For the output issue, you can't echo an echo in php. Try this instead:

$ev_link = tribe_get_event_link();
$ev_title = get_the_title();
printf('<a href="%1$s" title="%2$s">%2$s</a>', $ev_link, $ev_title);

Upvotes: 2

Related Questions