woocommerce pagination_link()不断向url添加参数

时间:2015-08-21 09:46:08

标签: php wordpress woocommerce

<div class="product-list-pagination clearfix">
<?php
    $page_url = esc_url_raw(remove_query_arg( array('add-to-cart'), get_pagenum_link( 999999999, false )));
    echo $page_url;
    echo paginate_links( apply_filters( 'woocommerce_pagination_args', array(
        'base'         => str_replace( 999999999, '%#%',  $page_url),
        'format'       => '',
        'add_args'     => False,
        'current'      => max( 1, get_query_var( 'paged' ) ),
        'total'        => $wp_query->max_num_pages,
        'prev_text'    => 'previous',
        'next_text'    => 'next',
        'type'         => 'list',
        'end_size'     => 3,
        'mid_size'     => 3,
        'show_all'     => False,
    ) ) );
?>

如果浏览器网址栏中的网址如下所示,我的代码出现问题:

http://localhost/vplay/shop/page/4/?orderby=date&add-to-cart=115

添加页面链接后,而不是从URL中删除add-to-cart = 115,它会继续将两个参数添加到页面URL 我希望我的网址是这样的:

http://localhost/vplay/shop/page/4/?orderby=date

注意当我回显$ page_url变量时,在paginate_links()函数中使用它后,URL保持正常,它会不断添加所有参数 现在该怎么做才能防止这种情况?

1 个答案:

答案 0 :(得分:0)

add_action('add_to_cart_redirect', 'resolve_dupes_add_to_cart_redirect');



function resolve_dupes_add_to_cart_redirect($url = false) {
    if(!empty($url)) { return $url; }

     return get_bloginfo('wpurl').add_query_arg(array(), remove_query_arg('add-to-cart'));
}

将以上内容插入您的function.php将解决问题。它确实适合我。