Home › Forums › General Issues › Display fields based on parameters in URL › Reply To: Display fields based on parameters in URL
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/
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.