Hello guys, Can someone please help me with this small code? <?php global $post; $args = array( 'posts_per_page' => 20, 'post_type'=> 'freeGallery', 'portfolio_cat' => 'Featured'); $myposts = get_posts( $args ); foreach( $myposts as $post ) : setup_postdata($post); ?> PHP: I have 46 posts in total. I want to show 20 posts per page. I added a pagination in the bottom of the page. The problem with my code is that only is showing 20 posts in total, I dont have page 2 and 3 in my pagination, only page 1. What I'm doing wrong? Thanks for any help you can give!!
How did you fix it? It would be helpful to post the resolution for anyone finding this thread in the future.
The main issue is that you are only showing us part of your code. If this is all of your code then you are missing key things which would add your other pages (So you see more than just page 1). You would want to declare that if the page provided was somehow 0 or a number higher than your pages make this page 1. Then you are going to need to query the DB to check the total number of records and use some arithmetic to break that into pages. There are many ways to skin this cat. However in your case your using the wordpress codex so you can just do this global $post; $args = array( 'posts_per_page' => 20, 'post_type'=> 'freeGallery', 'portfolio_cat' => 'Featured'); $myposts = get_posts( $args ); foreach( $myposts as $post ) : setup_postdata($post); { $posts[] += $post->ID; } $current = array_search( get_the_ID(), $posts ); $prevID = $posts[$current-1]; $nextID = $posts[$current+1]; ?> <div class="navigation"> <?php if ( !empty( $prevID ) ): ?> <div class="alignleft"> <a href="<?php echo get_permalink( $prevID ); ?>" title="<?php echo get_the_title( $prevID ); ?>">Previous</a> </div> <?php endif; if ( !empty( $nextID ) ): ?> <div class="alignright"> <a href="<?php echo get_permalink( $nextID ); ?>" title="<?php echo get_the_title( $nextID ); ?>">Next</a> </div> <?php endif; ?> </div><!-- .navigation --> Code (markup):