WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Custom Post Type Pagination (14 posts)

  1. OrT
    Member
    Posted 2 years ago #

    There's been a LOT written on custom post type pagination, but I still can't seem to be able to fix it.

    Here's the code:
    http://pastebin.com/1Lte6v7v

    Whenever I try to use:
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 0;

    It breaks everything completely.

    Thanks for your time and efforts!

  2. Ghalt
    Member
    Posted 2 years ago #

    If I'm reading the documentation correctly, depending on what version of WP you're using, it should be 'page', not 'paged'.

    From the documentation on wp_query:

    Pagination Note: You should set get_query_var( 'page' ); if you want your query to work with pagination. Since WordPress 3.0.2, you do get_query_var( 'page' ) instead of get_query_var( 'paged' ). The pagination parameter 'paged' for WP_Query() remains the same.

  3. OrT
    Member
    Posted 2 years ago #

    I'm on the latest version.
    Changing to page also breaks the query.

    $temp = $wp_query;
    $wp_query= null;
    
    $paged = (get_query_var('page')) ? get_query_var('page') : 0;
    
    $args=array(
    'post_type' => 'Nieuws',
    'paged' => $paged,
    'posts_per_page' => 2,
    'order' => 'desc'
    );
    
    $wp_query = new WP_Query($args);
  4. Digital Raindrops
    Member
    Posted 2 years ago #

    You do not need the line:

    $paged = (get_query_var('page')) ? get_query_var('page') : 0;

    If I am right WordPress will populate and return the $paged variable in the query, so you do not need to set it.

    $args=array(
    'post_type' => 'Nieuws',
    'paged' => $paged,
    'posts_per_page' => 2,
    'order' => 'desc'
    );
    $wp_query = new WP_Query($args);

    HTH

    David

  5. OrT
    Member
    Posted 2 years ago #

    David, thanks for your time.

    Same deal as before, the pagination is shown but /page/2/ throws back a 404 error.

  6. OrT
    Member
    Posted 2 years ago #

    Extra: htaccess is fine, /%category%/%postname%/ is the permalink structure.

  7. Digital Raindrops
    Member
    Posted 2 years ago #

    Hi,
    I have tested this with this testing twenty eleven child theme, I added the code below as a template page to display the custom post types of 'information' with pagination and it worked file.

    The template page code: http://pastebin.com/T257N6qW

    Note:
    My URL shows as ?page_id=61&paged=2, so yours is missing &paged=

    Changed my permalink structure /%category%/%postname%/ (/page/2/) and I do not get the same error as you!

    Pagination works fine!

    HTH

    David

  8. Digital Raindrops
    Member
    Posted 2 years ago #

    Just looking at your pastebin again and you are using the plugin wp_navigate, have a look in the twenty eleven theme at the functions.php and the function twentyeleven_content_nav

    It uses these variables and calls to return the output:

    global $wp_query;
    if ( $wp_query->max_num_pages > 1 ) :
       previous_posts_link()
       next_posts_link()
    endif;

    also try wp-pagenavi as I know this works with pagination as I use it on my website, so you can see it working.

    HTH

    David

  9. OrT
    Member
    Posted 2 years ago #

    I'm using wp_paginate() actually, which is working fine on a number of other sites I'm running.

  10. Digital Raindrops
    Member
    Posted 2 years ago #

    Hi,
    I adjusted my pastebin and tested with the plugin wp-pagenavi and it worked fine.
    http://pastebin.com/RPcsx1iy

    I then downloaded and activated wp-paginate changed the template code and that also worked fine, so both work with custom type pagination and your permalink structure,

    Screenshot of pagination

    Not sure what is going on, can you pastebin the whole page code!

    David

  11. OrT
    Member
    Posted 2 years ago #

    Update: for reasons unknown, I've managed to get it working.

    New problem: all other queries on /page/* are broken.

    Even if I put their queries in a separate object and reset the variables:

    $temp =  clone $wp_query;
    $wp_query = null;
    ...
    <?php $wp_query = null; $wp_query = clone $temp; ?>
    <?php wp_reset_postdata(); ?>
    <?php wp_reset_query(); ?>
  12. OrT
    Member
    Posted 2 years ago #

    David - my guess is the 'Types' plugin was causing the problems. Fiddled around with it, reactivated it, and suddenly the posts appeared.

  13. Digital Raindrops
    Member
    Posted 2 years ago #

    Does that mean the topic is resolved?

    David

  14. OrT
    Member
    Posted 2 years ago #

    According to the title of the thread, I believe it is.
    For the next problem I should open a new one that's relevant.

    Thanks very much for your assistance, David!
    Mucht appreciated.

Topic Closed

This topic has been closed to new replies.

About this Topic