WordPress.org

Ready to get started?Download WordPress

Forums

WP-PageNavi
[resolved] Wp page navi on custom post type page (10 posts)

  1. slaifer
    Member
    Posted 3 years ago #

    Hello i'm currently using custom post type on a page template, this is the code :

    <?php
    	$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    	$loop = new WP_Query( array( 'post_type' => 'myposttype', 'posts_per_page' => 4, 'paged'=>$paged ) ); ?>  
    
    	<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    
    	.....loop code...
    
    <?php endwhile; ?>
    
    	<?php wp_pagenavi(); ?>

    If i use the normal pagination everything works but if i use

    <?php wp_pagenavi(); ?>

    nothing shows on my page... how to fix this ? thanks

    EDIT : i've checked in wp page navi settings the option

    "Show navigation even if there's only one page."

    and now it shows some sort of navigation on my page but it says that there is only 1 page but it's not true, there are 2 page... what's going on ?

  2. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    It doens't work because it checks the global $wp_query.

    In the development version (2.74-alpha), you can do this:

    wp_pagenavi( array( 'query' => $loop ) );

  3. slaifer
    Member
    Posted 3 years ago #

    thank you so much now it works :).

  4. Dying2Live
    Member
    Posted 3 years ago #

    Hi,

    I'm also calling custom post types. I got mine to show up, but when you click on page2 or page3 of pagenavi I get a 404 page.
    http://www.monsterwheellaboratories.com/grandprix/pit-crew

    I'm using this code:

    <?php $my_query = new WP_Query( array( 'post_type' => 'pit-crew', 'posts_per_page' => 4, 'paged' => get_query_var('paged') ) ); ?>
    			<?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
                    <div id="card-wrap">
                        <img src="<?php echo get_post_meta($post->ID, "crewcard", true); ?>" alt="<?php the_title(); ?>" />
                    </div>
                <?php endwhile; ?>
                <?php wp_pagenavi( array( 'query' => $my_query ) ); ?>
                <?php wp_reset_postdata(); ?>

    If anyone can help me out it would be greatly appreciated.
    Thanks in advance.

  5. sacredpractice
    Member
    Posted 3 years ago #

    wish i could help @dying2live... my issues with pagenavi are tht it is not even showing he full amount of items in my custom post type. keeps saying page 1 of 1 but there are at least 20 items on my custom post type.

    any help scribu would be great. i'm going to post a more in depth description here in the forums... thnx

  6. Dying2Live
    Member
    Posted 3 years ago #

    @sacredpractice:
    It turns out my code was working correctly. The problem was I was using custom permalinks /%category%/%postname% and pagenavi was not recognizing it. All I did was revert back to default permalinks and save the changes. I refreshed my browser then went back in to permalinks and and rechecked custom and entered in /%category%/%postname% and save the change. after I did that everything was working perfectly.

    I hope that that helps you.

  7. sacredpractice
    Member
    Posted 3 years ago #

    thanks @dying2live

    i tried what you suggest but still only get "Page 1 of 1"!

    i am using a post template created from the single.php (template called single-events.php)... maybe this the issue? I am not using a page template instead a post template for my custom post type items?

    here is a link to my code and problem with pagenavi:

    http://wordpress.org/support/topic/pagenavi-plug-in-is-not-working-in-custom-post-types?replies=1#post-2004429

    any help is appreciated. thnx in advance.

  8. Nithin K Variar
    Member
    Posted 3 years ago #

    Thanks scribu

  9. homemrobo
    Member
    Posted 3 years ago #

    For those who have 404 problems with a custom post type indexing template, try to set 'with_front' to true:

    'rewrite' => array( 'slug' => 'portfolio', 'with_front' => true),

  10. Redefine
    Member
    Posted 3 years ago #

    The trick is to ensure your page template does not have the same slug as the custom post type slug.

    I took me some time to figure it out.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic