3

How I can insert some custom url parameters to pagination links? the code below display like

page.php?cpage=2

But I would like to add a parameter category with value fruit. So, the final url will look like below.

page.php?cpage=2&category=fruits

and so on..

page.php?cpage=2&category=fruits&color=red&size=small

Where and how do I insert the code to make the above happen?

  echo paginate_links( array(
    'base' => add_query_arg( 'cpage', '%#%' ),
    'format' => '',
    'prev_text' => __('«'),
    'next_text' => __('»'),
    'total' => ceil($total / $items_per_page),
    'current' => $page
  ));

thanks in advance

4

Use the add_args parameter to add an array of query string arguments to pagination links:

  echo paginate_links( array(
    'base' => add_query_arg( 'cpage', '%#%' ),
    'format' => '',
    'prev_text' => __('«'),
    'next_text' => __('»'),
    'total' => ceil($total / $items_per_page),
    'current' => $page,
    'add_args' => array(
        'category' => 'fruit',
        'color' => 'red'
    )
  ));
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.