$url = new moodle_url('/mod/forum/view.php', array('id' => 1, 'discussionid' => 2)); $newurl = $url->out_omit_querystring(); // Output: /mod/forum/view.php
$url = new moodle_url('/mod/forum/user.php', array('id' => 1, 'sort' => 'name', 'order' => 'asc')); $newurl = $url->out_omit_querystring('sort'); // Output: /mod/forum/user.php?order=ascIn the first example, the out_omit_querystring function removes all query strings from the URL, while in the second example, it only removes the 'sort' query string parameter. The Moodle_url class and the out_omit_querystring function are part of the Moodle core library.