user3534166 user3534166 - 1 year ago 94
PHP Question

Dynamic query string php

I am building a job board on our Wordpress website and each job has an Apply Now but which redirects to a form. Rather than build a new form for each job, I am trying to pass the Job Title (which is the page title) to the form but cannot get it to work.

So the button is located on this page for example:

Page title is Engineering Job

The code for the button I'm trying is this..

<button onclick="window.location.href='". $_GET["$title"] ."'">APPLY NOW</button>

Any idea how I can get the title into the query string so it would pass to my form as Job

Answer Source

You could use WordPress' wp_title() function and then urlencode() to properly encode all special characters.

<button onclick="window.location.href='<?php echo urlencode(wp_title(' ', FALSE)); ?>'">APPLY NOW</button>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download