-2

unset m=1 parameter values to null

abc.com/s=hotels&m=1

I have tried to unset using this code

function resetM() {
    if( isset( $request['m'] )){
        unset( $request['m'] );
    }
    return $request;
}

add_filter('resetM','request');

i want to &m=1 in url but the value of m is set to null

can any one help me in this

MH2K9
  • 11,951
  • 7
  • 32
  • 49
uDAY
  • 21
  • 1
  • 5
  • So you want to remove the `get` params from the URL itself, or you just want to set the variable to `null`? – Martin Dimitrov Aug 02 '19 at 10:25
  • You can get the value of an URL parameter using $_GET['parameter_name']. Thus, you get the value of `m` using `$_GET['m']` instead of $request['m']. To unset it use `unset($_GET['m']);` – Dejvid Aug 02 '19 at 10:26
  • 1
    did you try `unset( $_GET['m'] );` – Regolith Aug 02 '19 at 10:26
  • It's not `$request`, it's `$_REQUEST` so your if-statement will _alway_ return false since `$request` will always be undefined in your function. – M. Eriksson Aug 02 '19 at 10:30
  • However! Your URL: `abc.com/s=hotels&m=1` doesn't have any URL parameters so there's nothing to get with `$_GET` or `$_REQUEST`. For it to be URL parameters, you need a question mark before the params: `abc.com/?s=hotels&m=1` or your parameters will be apart of the URL itself. Otherwise, a simple: `$_GET['m'] = null;` would set it to null. – M. Eriksson Aug 02 '19 at 10:34
  • hi @MartinDimitrov i just want to set the variable to null – uDAY Aug 02 '19 at 10:35
  • @uDAY then you can just use what the others have mentioned `unset($_GET["m"]);` – Martin Dimitrov Aug 02 '19 at 10:36
  • You should also read the manual about [add_filter()](https://developer.wordpress.org/reference/functions/add_filter/). It looks like you've flipped the two first arguments. The first argument should be the tag and the second should be the callback function. – M. Eriksson Aug 02 '19 at 10:45
  • Your filter code is wrong, for more details you can check - https://codex.wordpress.org/Plugin_API/Filter_Reference/request – Shivendra Singh Aug 02 '19 at 10:57

1 Answers1

0

Thanks for reply

i have tweak my code and its working for me

add_action("init","remove_m_parameter");
function remove_m_parameter()
{
  if(isset($_GET['m']))
  {
  unset($_GET['m']);
  }
}
uDAY
  • 21
  • 1
  • 5