Home › Forums › General Issues › Display fields based on parameters in URL
I have dozens of insurance agents that i want to allow them to share a link to a general landing page that can be dynamically populated with their own unique contact info. I assume I can do this with creating an ‘agent’ CPT with their data (ie: phone, email address, etc) and pass the parameters in the URL to the landing page (ie: mydomain.com/landing-page(parameters)) So, two questions – when a person visits the landing page, how do i force the landing page to use the custom field values from a specific agent CPT? Second question, how do i call that info into the template?
Some things to keep in mind. I am going to be creating landing pages frequently going forward in the future. Also, the agents are coming and going within the company.
1) You supply the post ID or the post to get the fields from. All ACF functions allow you to do this https://www.advancedcustomfields.com/resources/get_field/
2) You get the parameter from the URL in the template. How you get this value depends if/how you set up WP to handle them and what the URL will look like exactly.
For example, using a simple $_GET value http://somesite.com/page/?agent=1
$post_id = false;
if (isset($_GET['agent'])) {
$post_id = intval($_GET['agent']);
}
It gets more complicated from there, for example you can create pretty URLs using rewrite rules and adding url parameters.
https://codex.wordpress.org/Rewrite_API/add_rewrite_tag
https://developer.wordpress.org/reference/functions/add_rewrite_rule/
https://premium.wpmudev.org/blog/building-customized-urls-wordpress/
ok. i think i am following, so in the template, would i use this to grab the phone for each agent?
<p><?php the_field('field_name', $post_id); ?></p>
For those who want my final code
http://somesite.com/page/?agent=1
$post_id = false;
if ( isset( $_GET[ 'agent' ] ) ) {
$post_id = intval( $_GET[ 'agent' ] );
$value = get_field( "phone", $post_id );
if ( $value ) {
echo $value;
} else {
echo 'empty';
}
}
}
how could this be modified such that the Agent parameter accesses a file on a cloud storage solution (like AWS S3).
Ex.
URL = somestime.com/page/?Agent=123456
Get’s = otherwise.com/folder/123456.mp4
… and that video 123456.mp4 is displayed on the template.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.