Pagination of custom post type leads to 404 error

Paste this function to your functions.php file if ( ! function_exists( ‘custom_pagination’ ) ) { function custom_pagination( $query_args ) { $big = 999999999; // need an unlikely integer $pages = paginate_links( array( ‘base’ => str_replace( $big, ‘%#%’, esc_url( get_pagenum_link( $big ) ) ), ‘format’ => ‘?paged=%#%’, ‘current’ => max( 1, get_query_var( ‘paged’ ) ), ‘total’ … Read more

Pagination with custom field

As I stated in comments, you need pre_get_posts and a meta_query to exclude posts from a certain custom field with a certain value from the main query. It is really in your best interest to read up on the before mentioned. Just remember, all parameters in WP_Query works on pre_get_posts as WP_Query uses pre_get_posts to … Read more

Paging + WP Query

pre_get_posts did the trick (thanks Pieter and cybmeta! Here’s the solution: function hwl_home_pagesize( $query ) { if ( is_post_type_archive( ‘motivation’ ) ) { $query->set( ‘posts_per_page’, 9 ); return; } if ( is_post_type_archive( ‘blog’ ) ) { $query->set( ‘posts_per_page’, 14 ); return; } } add_action( ‘pre_get_posts’, ‘hwl_home_pagesize’, 1 ); That’s it!

Add pagination to a template loaded by query variable

After a bit of digging over the weekend, I found the solution and indeed, it is a rewrite rule with the paged variable added add_rewrite_rule(‘collection/men/page/([^/]+)/?$’,’index.php?post_type=collection&men=yes&paged=$matches[1]’,’top’); Pagination now works in the custom template loaded by query variable. i.e. localhost/sample-site/collection/men/page/2 loads the next page instead of a 404 error

Conditional pagination li’s

Yes, but it is really more PHP than WordPress. You just need to reorder things and add some logic: $next = get_next_posts_link( ‘Previous’, $the_query->max_num_pages ); $previous = get_previous_posts_link( ‘Next’ ); if(!empty($next)) { $links[] = ‘<li class=”next”>’.$next.'</li>’; } if(!empty($previous)) { $links[] = ‘<li class=”previous”>’.$previous.'</li>’; } if (!empty($links)) { ?> <nav class=”post-nav clear clearfix”> <ul><?php echo implode($links); … Read more

Custom pagination (Previous / Next)

Well… pretty much just do exactly what you said. Add a class conditionally based on the number of links O.o $link_container_class=””; if (!empty($links)) { if( 1 === count( $links ) ) { $link_container_class=”single”; } ?> <nav class=”post-nav clear clearfix <?php echo $link_container_class; ?>”> <ul><?php echo implode($links); ?> </ul> </nav><?php } ?>

Pagination, query more pages at once

offset would skip posts, it sounds like you want the current page number * the number of posts per page- $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $posts_per_page = $paged * get_option(‘posts_per_page’); $args = array( ‘posts_per_page’ => $posts_per_page ); You’ll need to keep in mind that total number of pages in the query object will … Read more

remove $_GET-parameter from WP_List_Table::tablenav

You should consider the POST request method for your action. Otherwise you might try to hijack the set_url_scheme filter with: add_filter( ‘set_url_scheme’, ‘wpse_remove_arg’ ); function wpse_remove_arg( $url ) { return remove_query_arg( ‘do_action_xyz’, $url ); } Then you could try to narrow the scope and only run this on the corresponding table page. Further you could … Read more

error code: 521