Ecommerce Shopify WordPress Discussion

Error 404 Not Found When turning pages in pagination in page Archiver product

I'm getting a 404 error when using Wordpress and Woocommerce at same time.I paginate the products in the archive page but when I switch to other pages except the first page, I get a 404 error. This is the code of the archive-product.php: <?php /** * The Template for displaying product archives, including the main shop page which is a post type archive * * This template can be overridden by copying it to yourtheme/woocommerce/archive-product.php. * * HOWEVER, on occasion WooCommerce will need to update template files and you * (the theme developer) will need to copy the new files to your theme to * maintain compatibility. We try to do this as little as possible, but it does * happen. When this occurs the version of the template file will be bumped and * the readme will list any important changes. * * @see https://woo.com/document/template-structure/ * @package WooCommerce\Templates * @version 3.4.0 */ defined('ABSPATH') || exit; get_header('shop'); global $wp_query; $paged = (get_query_var('paged') != 0 && is_int(get_query_var('paged'))) ? get_query_var('paged') : 1; $args = [ 'post_type' => 'product', 'posts_per_page' => 2, 'paged' => $paged, ]; query_posts(array_merge($args, $wp_query->query)); ?> <div class="archive_product_container"> <?php /** * Hook: woocommerce_before_main_content. * * @hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content) * @hooked woocommerce_breadcrumb - 20 * @hooked WC_Structured_Data::generate_website_data() - 30 */ woocommerce_output_content_wrapper(); //do_action('woocommerce_before_main_content'); ?> <?php if (woocommerce_product_loop()) { /** * Hook: woocommerce_before_shop_loop. * * @hooked woocommerce_output_all_notices - 10 * @hooked woocommerce_result_count - 20 * @hooked woocommerce_catalog_ordering - 30 */ do_action("woocommerce_before_shop_loop"); woocommerce_product_loop_start(); if (have_posts()) { while (have_posts()) { the_post(); /** * Hook: woocommerce_shop_loop. */ do_action('woocommerce_shop_loop'); wc_get_template_part('content', 'product'); } wp_reset_postdata(); // Đặt ngay sau vòng lặp while } woocommerce_product_loop_end(); /** * Hook: woocommerce_after_shop_loop. * * @hooked woocommerce_pagination - 10 */ $total_pages = $wp_query->max_num_pages; if ($total_pages > 1) { $current_page = max(1, get_query_var('paged')); paginate($current_page, $wp_query); } do_action('woocommerce_after_shop_loop'); } else { /** * Hook: woocommerce_no_products_found. * * @hooked wc_no_products_found - 10 */ do_action('woocommerce_no_products_found'); } /** * Hook: woocommerce_after_main_content. * * @hooked woocommerce_output_content_wrapper_end - 10 (outputs closing divs for the content) */ do_action('woocommerce_after_main_content'); /** * Hook: woocommerce_sidebar. * * @hooked woocommerce_get_sidebar - 10 */ ?> <div class="filter"> <h2>Bộ lọc</h2> <hr> <?php do_action('woocommerce_sidebar'); ?> </div> </div> <?php get_footer('shop'); And here is the code of the page transfer link fuction function paginate($current_page, $query = null) { $pages = $query->max_num_pages; echo '<div class="pagination">'; echo '<div class="prev-next-links">'; if ($current_page > 1) { echo '<a href="' . get_pagenum_link($current_page - 1) . '" class="prev"><i class="fa-solid fa-angle-left"></i></a>'; } echo '</div>'; echo '<div class="page-numbers">'; for ($i = 1; $i <= $pages; $i++) { echo '<a href="' . get_pagenum_link($i) . '" class="page-number ' . ($current_page == $i ? 'current' : '') . '">' . $i . '</a>'; } echo '</div>'; echo '<div class="prev-next-links">'; if ($current_page < $pages) { echo '<a href="' . get_pagenum_link($current_page + 1) . '" class="next"><i class="fa-solid fa-angle-right"></i></a>'; } echo '</div>'; echo '</div>'; } I tried change from paged to page but the result is still error 404
TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.