The code that I'm using has adapted from this example and successfully tested on my localhost but when I pass the site to a live server, the pagination crashes with wordpress permalinks set (/% postname% /) and only works with the default wp permalinks (? p = 123). The problem is that it doesn't show me any 404 page, but it also doesn't let me go to the second or third pages, or any other's if they exist.
This is a listing (custom postype) page (single-listing.php) and I have the page like this:
- The current single listing content;
- This code (to list all posts by the author of that listing);
- Related listings
I've done some research and even tried to replace "paged" because the query var for paginated archives and single posts should use "page" and followed @pietergoosen hint regarding this notice by turning On mysql.trace_mode in my local php.ini. After that I've restarted all services in wampp and the pagination on localhost has working, so I don't think that this could be the problem.
This is my code:
<?php global $authordata, $post; $paged = ( get_query_var('page') ) ? get_query_var('page') : 1; $args = array( 'author' => $authordata->ID, 'post_type' => 'post', 'post__not_in' => array( $post->ID ), 'posts_per_page' => 3, 'paged' => $paged ); $authors_posts = new WP_Query( $args ); if( $authors_posts->have_posts()) : while( $authors_posts->have_posts()) : $authors_posts->the_post(); ?> <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" ><?php the_title(); ?></a> <?php the_post_thumbnail( array(80,135));?> <?php $excerpt = get_the_excerpt(); echo string_limit_words($excerpt,40);?> <?php endwhile; ?> <?php if($authors_posts->max_num_pages) if(function_exists('wp_pagenavi')) wp_pagenavi(array( 'query' =>$authors_posts )); ?> <?php endif; wp_reset_query(); ?>
I've select the @pietergoosen answer as the one that solved my problem, but I didn't get it why my code stop working a live server. Now, I probably will never make use of that information, but I will surely like to know why my code works on localhost (using wampserver) and not on a live server...
If you know the answer to this question, please comment. Thanks!