Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
possible duplicate of Pagination not working with custom loop –  Chip Bennett Jan 27 '12 at 17:29
add comment

1 Answer

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()

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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