paginate_links pagination with new variable pg

I would like to add new parameter “pg” as page number with help of paginate_links().

My website:

https://www.dealfinder.lk/search/?deal=happy-hour&pg=2

Here is my function :

echo paginate_links( array(
‘base’ => get_pagenum_link(1) . ‘%_%’,
‘format’ => ‘&pg=%#%’,
‘current’ => max( 1,$paged ),
‘total’ => $query_search->max_num_pages,
‘prev_text’ => ‘”‘,
‘next_text’ => ‘»’,
‘add_args’ => array(
‘deal’ => get_query_var(‘deal’)
)
) );

Please note I have added query string “deal”.

It prints follow :

https://www.dealfinder.lk/search/?deal=happy-hour&pg=2

https://www.dealfinder.lk/search/?deal=happy-hour&pg=3

https://www.dealfinder.lk/search/?deal=happy-hour&pg=4

It looks perfect but when I go to page second or third or fourth. It gives me wrong links. Please check below :

https://www.dealfinder.lk/search/?deal=happy-hour#038;pg=2&pg=2

https://www.dealfinder.lk/search/?deal=happy-hour#038;pg=2&pg=3

https://www.dealfinder.lk/search/?deal=happy-hour#038;pg=2&pg=3

As you can see above links are not proper. its added two times parameter “pg”.

Thanks.

Read more here:: paginate_links pagination with new variable pg

Leave a Reply

Your email address will not be published. Required fields are marked *