WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Need Help With Cranky Pagination on Page Templates (5 posts)

  1. mmachine
    Member
    Posted 4 years ago #

    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?

  2. Equal Web Creative
    Member
    Posted 4 years ago #

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

  3. keesiemeijer
    moderator
    Posted 4 years ago #

    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; ?>
  4. mmachine
    Member
    Posted 4 years ago #

    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.

  5. keesiemeijer
    moderator
    Posted 4 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic