i'm using the events calendar plugin and at some place i use the tribe_get_events() function to show the upcoming events. Point is, i need to create a pagination for those results.

The tribe_get_events function is using wordpress' get_posts() and accepts some parameters like posts_per_page. I've tried adding some pagination parameters as i would with a WP_Query() request but without any success yet.

Here goes the code:

<?php global $post; 
$all_events = tribe_get_events(array( 'eventDisplay'=>'upcoming', 'posts_per_page'=> 3, ));
foreach($all_events as $post) {
    setup_postdata($post); ?>

    <?php the_title(); ?>

<?php } wp_pagenavi();  wp_reset_query(); ?>

The 'paged' => get_query_var('paged') does change anything. Am also using the WP-PageNavi plugin but if there's a way to get the navigation working here without it it'd be already fine.


Set the offset manually.

$offset = ( get_query_var( 'page' ) ) ? get_query_var( 'page' ) : my_parse_url_for_offset();

function my_parse_url_for_offset() {
    if( strpos( $_SERVER['REQUEST_URI'], '/page/' ) !== false ) {
        $url = explode( '/', $_SERVER['REQUEST_URI'] );
        $url_c = count( $url );

        for( $i = 0; $i < $url_c; $i++ ) {
            if( $url[$i] == 'page' ) {
                if( is_numeric( $url[$i+1] ) )
                    $page = $url[$i+1];
    } else {
        $page = 1;
    return $page;

then feed it as an arg in get_posts()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.