WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Need Help With Cranky Pagination on Page Templates

[Resolved] Need Help With Cranky Pagination on Page Templates

  • I’m building a theme with a page template that queries posts with the following code:

    $temp = $wp_query;
    $wp_query= null;
    $wp_query = new WP_Query();
    $wp_query->query('post&paged='.$paged); ?>

    This works great, and pagination is no problem. However, on another page template, I’m using the exact same method, yet I’m changing the search criteria to query based on post_type. That code is:

    $temp = $wp_query;
    $wp_query= null;
    $wp_query = new WP_Query();
    $wp_query->query('post_type=television&paged='.$paged);

    That code works to pull and display the proper ‘television’ posts, but my pagination breaks when trying to view page 2 — I get a “Page not found error”.

    What’s the deal here? Am I querying custom posts improperly?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Equal Web Creative
    Member

    @equalwebcreative

    I am having the same problem to when used with a custom post type query.

    keesiemeijer
    Moderator

    @keesiemeijer

    try this
    Put this before the loop

    $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $temp = $wp_query;
    $wp_query= null;
    $wp_query = new WP_Query();
    $wp_query->query('post_type=television&paged='.$page);

    and this behind the loop:

    <?php endwhile; //end of loop ?>
    <?php $wp_query = null; $wp_query = $temp; ?>

    keesiemeijer, thanks! This didn’t solve my problem, but it’s actually a pagination technique I could definitely use.

    As to what did solve my problem, it was having to do with the page URL being the same as the custom post name. So, my page was ‘/television/’, and my custom post type is ‘television’, so WordPress wasn’t letting me go past the first page. Confusing, because if I try viewing /television/ by itself, there’s no default rendering or the custom post types, so I’m not exactly sure what call WordPress is protecting.

    keesiemeijer
    Moderator

    @keesiemeijer

    Glad you found the solution! Now, please use the dropdown at top right to mark this topic ‘Resolved’.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] Need Help With Cranky Pagination on Page Templates’ is closed to new replies.