4

I want to add query parameter to my current url, I'm getting current url in my phtml like this:

$current_url = $this->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true]);

I want to add query parameter to my url so it will look like this:

https://currenturl.com?new_query=123

And when the current url already has another query parameter, it will look like this:

https://currenturl.com?old_query=22&new_query=123

1 Answer 1

13

Try this

$current_url = $this->getUrl('*/*/*', array('_current' => true,'_use_rewrite' => true, '_query' => $your_query));

Where

 $your_query = array('new_query' => 123)
4
  • what is inside $your_query ? Commented Nov 16, 2017 at 8:54
  • 1
    It's works for me Commented Nov 16, 2017 at 8:59
  • Which file need to edit to add query param? Commented Oct 4, 2019 at 13:44
  • how can i get or echo the current url with the query parameter in phtml file?
    – Ali Raza
    Commented Sep 17, 2021 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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