Johnny
Johnny

Reputation: 576

Wordpress Pagination Not Working - Always Showing First Pages Content

I am working on a website where I have a blog but I also have a custom post type to allow me to drop in some videos.

I would like to use pagination so that if there are more then 9 videos displayed, then pagination occurs.

The first part of this works. The videos are indeed limited to 9 per page and the pagination correctly shows up at the bottom.

However when I click on the link for the second page, even though the URL changes, the first pages videos are displayed.

For my 'normal' blog posts, pagination is working exactly as intended.

This is the current code that I am using for my custom post type:

<?php if ( have_posts() ) : ?>
    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts('post_type=videos&posts_per_page=9&paged=$paged'); ?>

        <?php /* Start the Loop */ ?>
        <?php while ( have_posts() ) : the_post(); ?>

Any help would be greatly appreciated.

Upvotes: 2

Views: 7941

Answers (2)

Johnny
Johnny

Reputation: 576

Not my own work but here is the answer explained brilliantly over in Wordpress Answers!

https://wordpress.stackexchange.com/questions/105977/wordpress-pagination-not-working-always-showing-first-pages-content

Upvotes: 0

wunderdojo
wunderdojo

Reputation: 1027

Depending on what page you're on (like a static homepage) WP uses the query var page, not paged. You can correct for that with something like this:

  if( get_query_var( 'paged' ) )
$my_page = get_query_var( 'paged' );
else {
if( get_query_var( 'page' ) )
    $my_page = get_query_var( 'page' );
else
$my_page = 1;
set_query_var( 'paged', $my_page );
$paged = $my_page;
}

Upvotes: 6

Related Questions