I use an API to get a list of jobs. I have created 3 templates. The 1st shows the list of jobs, the 2nd the details of the job selected and the 3rd a form. To create the URL for the form I must use a variable $reference which equals to "ref/ClientName".

But when I click on the button that redirect to the form template, the URL is changed. The "/" in the variable $reference is removed so it becomes "refClientName" instead of "ref/ClientName".

How can I make WordPress to keep my variable with the "/"? Thanks

This what I've tried

//$ref = $_GET['ref'];

global $wp_query;

$ref = $wp_query->query_vars['ref'];


The ref=$ref stores the variable

  • Hello can you share more information about how your pages are setup? Are you using rewrite rules? Do you have examples of the URLs? Is the ref/ClientName part going in the URL or as a parameter e.g. foo/?ref/ClientName=bar? I see there is no code in your question. Use the edit link to update it with as much detail as possible so that it's clear what you're asking. Could you just add the / back in when making requests to the API? – Tom J Nowell Mar 9 at 14:50
  • Hello, I'm not using rewrite rules because I have not succeeded in making it work. The ref/ClientName part is going in the URL. The URL should be e.g "www.domain.com/apply/123/SI" with "123/SI" equal to ref/ClientName. I Have edited my post. Hope it helps understand my issue – Skemby Mar 9 at 15:22
  • You can only use $wp_query->query_vars["ref"] if you add ref via query_var` filter. Have you already done that? – Cadu De Castro Alves Mar 9 at 16:05
  • Why don't you just write $json=file_get_contents("[..]&ref=ref/$ref&lang=fr"); and use only 'ClientName' in your WordPress URL? – chrisbergr Mar 9 at 16:43
  • @CaduDeCastroAlves I have not added ref via quer_var_filter. Should I use it in my functions.php ?. @chrisbergr Because the value of $ref is a whole. I stored the 'job_reference' from the API in my variable $reference. This is in the 2nd template $job = json_decode($json, TRUE); $reference = $job['job_reference']; $link0 = $job['job_id']; Then I have created a button <a href='/apply/$reference'> This redirect to the final template that is the form. But in the URL the $reference which is supposed to be 'ref/ClientName' doesn't have the '/' in it. – Skemby Mar 10 at 6:49

Your Answer

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

Browse other questions tagged or ask your own question.