WordPress pagination gives 404 error with custom wp_query
-
The category “example” has no posts. However, for user navigation and SEO purposes, this category carries a query by keyword “example”:
category.php or archive.php
$current_category = single_cat_title("", false); $args = array( 's' => $current_category, //search 'posts_per_page' => 20, 'orderby' => 'rand' ); $wp_query = new WP_Query( $args );
It works perfectly! The problem is pagination. It correctly displays the number of pages, but to access the page 2 appears page not found (404).
Permalink – Custom Structure:
/%category%/%postname%/Links (examples):
https://site.com/category/example – ok! (
opens the last 20 posts and displays links to pages)https://site.com/category/example/page/2/ – !fail! (Error 404 – Not Found)
https://site.com/category/example/?paged=2 – !fail! (Error 404 – Not Found)
Plugins or custom pagination: both fail.
Other categories with posts, or tags, search, pagination functions normally.Research and tests that have not given results:
https://www.bamboosolutions.co.uk/fix-404-errors-wordpress-pagination/
https://stackoverflow.com/questions/22364294/pagination-on-custom-wp-query-in-wordpress-takes-to-404-error-page
https://www.ads-software.com/support/topic/custom-post-type-query_posts-pagination-404-error?replies=16
https://www.ads-software.com/support/topic/error-404-on-pagination-when-changing-posts_per_page-on-query_posts?replies=16https://codex.www.ads-software.com/Function_Reference/paginate_links
https://codex.www.ads-software.com/Class_Reference/WP_Query#Pagination_Parameters
And all the other links, hack, plugins, scripts of the first pages of Google or WP Forum.I appreciate any suggestions. Thank you.
- The topic ‘WordPress pagination gives 404 error with custom wp_query’ is closed to new replies.