• Hello there,

    I’m not sure if anyone is able to help me but I’m trying to create a shortcode that will display a list of upcoming events in date order from the _EventStartDate meta.

    Here is what I have so far…

    /*************************************************************************
    	* Shortcode - What's Next
    	*************************************************************************/
    	add_shortcode('jmit_events_whatsnext', 'jmit_events_whatsnext_shortcode');
    	function jmit_events_whatsnext_shortcode(){
    		global $post;
    		ob_start();
    
    		$args = array( 'posts_per_page' => 2, 'post_type' => 'tribe_events' );
    		$lastposts = get_posts( $args );
    		foreach ( $lastposts as $post ) :
    		  setup_postdata( $post ); ?>
    			<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    			<?php the_content(); ?>
    		<?php endforeach;
    		wp_reset_postdata(); 
    
            $myvariable = ob_get_clean();
            return $myvariable;
    	}

    However it does not appear to respond to the ‘posts_per_page’ argument, it just lists every event.

    Has anyone got any ideas or pointers?

    Thanks very much!
    Jason

    http://ww.wp.xz.cn/plugins/the-events-calendar/

Viewing 1 replies (of 1 total)
  • Hi Jason,

    Always great to see people building extensions like this 🙂

    Actually it works for me as expected and if I tweak the posts_per_page parameter to 3, 4 or 5 posts it also works as expected. Do you definitely have more than 1 upcoming event? How many posts are you seeing returned?

Viewing 1 replies (of 1 total)

The topic ‘Shortcodes’ is closed to new replies.