'Pulling data from a URL to insert in WordPress text
I'm just getting started with WordPress and have no prior experience with coding. I was wondering if someone could help me perform this task :
I am basically trying to pull data from a URL: https://equipelupien.com/partenaires-perso?calendly=jplupien&nomDu=stevenchose
I want the data nomDu=stevenchose to populate in a text field in WordPress. To give context, it's for a mortgage broker firm, and this page is made for a customer who wants to book an appointment referred by a partner. So in my text, we would read Fill out the form above to make an appointment with a broker referred by (here my data from URL)
Solution 1:[1]
You pull the data (the query string) from the $_GET array.
So to output in a text box it would look like this for WordPress
<input type="text" value="<?= sanitize_text_field($_GET['nomDu']); ?>" />
Some explanation:
<?=is short for<?php echosanitize_text_fieldis a WordPress core function that removes tags from the string that you cannot trust.esc_attralso could be used instead (difference)
You could also add it as a shortcode:
add_shortcode('nom-du-text', function(){
return '<input type="text" value="' . sanitize_text_field($_GET['nomDu']) . '"/>'
});
Then you could use [nom-du-text] from the post editor.
Finally, to simple output this as text just add <?= sanitize_text_field($_GET['nomDu']); ?> to the page PHP template.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Josh Bonnick |
