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 looking for a way to paginate my get_posts :

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                $args = array(
                    'posts_per_page'   => 5,
                    'offset'           => 0,
                    'orderby'          => 'post_date',
                    'order'            => 'DESC',
                    'post_type'        => 'post',
                    'post_status'      => 'publish',
                    'suppress_filters' => true,
                    'paged'            => $paged,
                    ); 

                $query = get_posts($args);

I've been trying to get this on my own but I did not succeed. Here is my paginate function :

function my_pagination($query = false){
global $wp_query;

if ( !$query ) $query = $wp_query;

$big = 999999999; // need an unlikely integer
    echo paginate_links( array(
        'base'         => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
        'format'       => '?paged=%#%',
        'current'      => max( 1, get_query_var('paged') ),
        'total'        => $query->max_num_pages,
        'type'         => 'list',
        'prev_text'    => __('%s Previous','textdomain'),
        'next_text'    => __('Next %s','textdomain'),
    ) );
}

I call it in my template with :

if ( function_exists('my_pagination') ) my_pagination($query);

Any help would be much appreciated.

share|improve this question
    
RESOLVED BY MYSELF –  JMau Aug 6 '13 at 15:59
    
If you post your solution as an answer and accept it, then others in the same situation can see a solved question. –  Pat J Aug 6 '13 at 16:15
    
What do I do now? It's impossible to accept my own answer ! –  JMau Aug 6 '13 at 16:38
    
You should be able to. (There might be a waiting period, though...) –  Pat J Aug 6 '13 at 16:40
    
ok ^^ I'll do it ASAP. –  JMau Aug 6 '13 at 16:41
show 1 more comment

1 Answer

up vote 1 down vote accepted

The solution to that was pretty simple. I just replaced get_posts() with a simple new WP_query() :

$query = new WP_query($args);

I guess now you have a ready-to-implement function for pagination ^^

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.