Support » Fixing WordPress » pagination 'add_args'

  • Hi there,

    I’m using ‘add_args’ to append a couple of vars into my pagination links.

    The code looks like this:

    function my_pagination()
    
    {
    
        global $wp_query;
        $big = 999999999;
        unset($urlArgs);
        $urlArgs = array('searchBar' => $_REQUEST['searchBar'], 'searchType' => $_REQUEST['searchType']); // add args for search/filter
    
        echo paginate_links(array(
            'base' => str_replace($big, '%#%', esc_url( get_pagenum_link($big))),
            'format' => '?paged=%#%',
            'current' => max(1, get_query_var('paged')),
            'total' => $wp_query->max_num_pages,
            'add_args' => $urlArgs
    
        ));
    
    }

    This works fine for the first page of results (all the pagination links are correct e.g: /page/1?searchBar=40&searchType=18)

    However if I click onto page 1 or 2 of the results all the pagination links become malformed with an extra parameter on the end (e.g. /page/1?searchBar=40&searchType=18#038;searchType=18)

    For some reason the searchType parameter is being added twice but I’m not sure where it’s coming from or why.

    Would be most grateful for any insight.

    Cheers.

  • The topic ‘pagination 'add_args'’ is closed to new replies.