1

Can i get the help of you guys as i want i can do it with url

I need to split the URL. and use last element as job_id, And then pass "jkdbsbd45JubJKAAASSYT" as job_Id.

URL: https://dev/job/?job_id=jkdbsbd45JubJKAAASSYT

Need to create this URL as below.

Need: https://dev/job/jkdbsbd45JubJKAAASSYT

Thanx in advance

1 Answer 1

2

Not really a WordPress related question but you could do this

// creates a object from the array, one of the properies (search) contains the query
let url = new URL('https://dev/job/?job_id=jkdbsbd45JubJKAAASSYT');
// will create a object of all availalble query properites
const urlSearchParams = new URLSearchParams(url.search);
const params = Object.fromEntries(urlSearchParams.entries());
// remove ? and everything after from url
url = url.href.substring(0, url.href.indexOf('?'));

// url + params.job_id is the final url, did a console.log so you could see it in the devtools console
console.log(url + params.job_id);
8
  • Still I am very happy that you helped me and gave your precious time. Commented Dec 29, 2021 at 7:02
  • One more question how to pass Id variable on this URL Like: let getId = "jkdbsbd45JubJKAAASSYT"; let url = new URL('dev/job/?job_id=', getId ); Commented Dec 29, 2021 at 7:21
  • 1
    @DKThakur In JS if you want to concatenate you need to use +, so going by what you want to achieve, you would need to do this URL('https://dev/job/?job_id=' + getId) Commented Dec 29, 2021 at 9:03
  • Thank you very much, this was out of my mind, and I am having an issue in WordPress, I do not have any knowledge of htaccess, can you help me? Commented Dec 29, 2021 at 9:15
  • @DKThakur You have a whole community that can help you. If you have a question about .htaccess that is WordPress related you can create a new question here, just make sure to check how to ask a good question Commented Dec 29, 2021 at 9:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.