Having trouble generating pagination links on custom query

Though all of the arguments are optional, paginate_links doesn’t necessarily do anything if there are no arguments. Take a look at the example at the example in the Codex.

global $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' => $wp_query->max_num_pages
) );

That works. Try it. Now remove the last parameter. See? Try passing that total to your function.

Again, please don’t use query_posts, especially for secondary loops. Use get_posts or create a new WP_Query object. I’d do the latter. I don’t think you’d really need to alter much.

$myquery = new WP_Query(
    array(
        'category_name' => $name, 
        'orderby' => 'date', 
        'order' => 'DESC', 
        'posts_per_page' => 1, 
        'paged' => $paged
    )
);

Leave a Comment