Custom Post Type Pagination On Front Page (10 posts)

  1. Justin Carroll
    Posted 4 years ago #

    Hello. I have a static front page called "Home". This page uses a page template called "Front Page" (page-home.php). In the template I'm doing a custom query to pull a custom post types called "Gallery". I'm trying to use WP PageNavi to paginate through these gallery items. And it's not working. It shows page 1 fine, but when you click on page 2 it just looks like page 1 again. Here's my code:

    $loop = new WP_Query( array( 'post_type' => 'galactic_gallery', 'paged' => get_query_var( 'paged' ), 'posts_per_page' => 1 ) );
    while ( $loop->have_posts() ) : $loop->the_post();
    	// output
    wp_pagenavi( array( 'query' => $loop ) );

    I also have a page template called "Gallery" that I use to show the same custom post types, but that page paginates just fine with the above code. It's something special going on with the query on the home page it seems, but I'm not sure.

    Any help would be appreciated. Thanks!

  2. Justin Carroll
    Posted 4 years ago #

    Found this fix by ThemeBlvd on the ThemeForest forums:

    if ( get_query_var('paged') ) {
        $paged = get_query_var('paged');
    } else if ( get_query_var('page') ) {
        $paged = get_query_var('page');
    } else {
        $paged = 1;
    query_posts( array( 'post_type' => 'post', 'paged' => $paged ) );

    Worked for me. Don't understand it. But it works. Thx!

  3. johnfrancisco
    Posted 4 years ago #


    It works also great for me. This is just perfect. Thks.
    It was driving me crazy!
    I was posting here with no solutions.

    (I also do not understand it. If someone could show us the light…)

  4. digitalrenewal
    Posted 3 years ago #

    This fix works BECAUSE wordpress uses two different yet similar variables to define regular posts and custom post types. The conditional (page and paged) tells wordpress which one to use.

    heres the full page template if anyone has trouble putting it all together.

    [Code moderated as per the Forum Rules. Please use the pastebin]

  5. scribu
    Posted 3 years ago #

  6. digitalrenewal
    Posted 3 years ago #

    hey scribu! that IS where i learned that, only I'd been through so many pages I couldnt begin to find the link back to you. I have a very beginning understanding of php, so you explained it well.

    heres that code in pastebin

  7. digitalrenewal
    Posted 3 years ago #

    Im seeing strange pagination behavior. I have created 4 custom post types. 2 of them, pagination works. The other 2, I get a 404. Im using Sparklette's enhanced pagination code, and the code referenced here to build the page templates.

    Anyone know what gives?

  8. digitalrenewal
    Posted 3 years ago #

    I found the answer here:

    You cant name the post type and the page (slug) the same name. Theres a fix on that thread as well.

  9. MateuszFlisikowski
    Posted 3 years ago #

    Hi, this solved my problem <- pastebin.com

  10. inTOWN
    Posted 3 years ago #

    @digitalrenewal ... That solution only seems to work on the actual page.
    So in my example: I have made a page called "Bridesmaids"
    with the template of the custom post type archive "Bridesmaid"

    If I point the browser to the page ("Bridesmaids") the pagenavigation works fine.
    But if I point the browser to the custom post typle link ("Bridesmaid"), even though it's the same template, now the navigation still doesn't work.

    Of course I added the page to my navigation menu, but what if someone ends up at "Bridesmaid" changing the deeplink?

Topic Closed

This topic has been closed to new replies.

About this Topic