Best way to pass arguments to another page in WordPress

What is the best way to pass arguments to another page in wordpress.
I did it this way :

<a href="https://wordpress.stackexchange.com/questions/5775/get_permalinka(id_of_page)."/&i=2&j=3&k=4'">Link/a>

I get this arguments with $_GET[‘i’],$_GET[‘j’],$_GET[‘k’],problem is : this works just with default permalinks,but when I change it to some other permalink type,it does not work any more.Note – I’m passing these arguments from homepage to another page(template page).

Thank you for your time.

2 Answers
2

Use add_query_arg() to do this.

Here’s a useful function if you need to get the current page URL (when get_permalink is inaccesible, like on Archives):

function get_current_page_url() {
  $request = esc_url($_SERVER["REQUEST_URI"]);

  $pageURL = (is_ssl() ? 'https' : 'http').'://';
  if ($_SERVER["SERVER_PORT"] != "80") $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$request; else $pageURL .= $_SERVER["SERVER_NAME"].$request;

  if (false === strpos(get_option('home'), '://www.')) $pageURL = str_replace('://www.', '://', $pageURL);
  if (false !== strpos(get_option('home'), '://www.') && false === strpos($pageURL, '://www.')) $pageURL = str_replace('://', '://www.', $pageURL);

  return $pageURL;
}

Leave a Comment