• Resolved harshclimate

    (@harshclimate)


    Hi everyone! I’m trying my hand at pagination and for the most part everything is working fine except:

    My pagination is querying a custom_post_type named arizona_wine. Posts per page is set at 1 (so I can cycle the pagination to make sure it works) but when I click page 2, it says “page not found” on my firefox tab.

    On home.php I have a tab called “All” which pulls in custom post types ‘arizona_wine’ and ‘arizona_beer’. The pagination works there, but when I go to the archive-arizona_wine.php and use the pagination it isn’t working as it does on home.php.

    The code on home.php is below – Will this code not work on archive-(archive name).php

    $currentpage = get_query_var('paged') ? get_query_var('paged') : 1;
    $args = array(
    'posts_per_page' => 12,
    'post_type' => array('arizona_wine', 'arizona_beer'),
    'orderby' => 'title',
    'order' => 'ASC',
    'paged' => $currentpage
    );
    $all_posts = new WP_Query($args);

    then the loop – then

    $big = 999999999;
    echo paginate_links(
    array(
    'base' => str_replace($big, '%#%', get_pagenum_link($big)),
    'format' => '?paged=%#%',
    'current' => max(1, get_query_var('paged')),
    'total' => $all_posts -> max_num_pages,
    'prev_text' => ('Previous'), 'next_text' => ('Next'),
    )
    );

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter harshclimate

    (@harshclimate)

    I ended up creating pages for arizona_wine & arizona_beer instead of using archive and it seems to be working as expected.

    Moderator bcworkz

    (@bcworkz)

    I’m glad you apparently found a solution. I’d like to point out that it’s kind of risky using the paged query var value in secondary queries or in paginate_links(). That value belongs to the query resulting from the HTTP request, the “main” query. The appropriate value for your secondary query may be different. Sometimes the values align and all is well. Other times the values diverge and you get unexpected page not found errors.

    For secondary queries I recommend implementing your own unique pagination query var and to not use paged for this.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.