I am new to Wordpress dev, and I have a page that loops through some custom fields(repeater) of people.
I'd like each subfield link to go to another page that has more info from that person on the previous page(same field group data). Is there a dynamic way to do this or do I need to create a new page for each person to show more details on link click?
I am new to Wordpress dev, and I have a page that loops through some custom fields(repeater) of people.
I'd like each subfield link to go to another page that has more info from that person on the previous page(same field group data). Is there a dynamic way to do this or do I need to create a new page for each person to show more details on link click?
You would at least need to create one page where you can list all the info. In the php template for that page, you can then change that info based on the page you're linking from.
That would be the same link for all pages though (you could get around that with rewrite rules, but that's a different story).
Say you're linking from a page with ID = 123. Create a new page "The New Page".
In your link you can do something like:
<a href="/the-new-page?id=<?php the_ID(); ?>">Read More</a>
In the template file of the new page, you add something like:
$previous_page_id = $_GET['id'];
$value = get_field('my-field', $previous_page_id);
if($value){
echo $value;
} else {
echo 'Sorry, no information found.';
}
I solved this by using this as my link, then doing a check on name to show the correct data in the new template:
<a class="btn" href="<?php echo esc_url( add_query_arg( 'n', $name, site_url( '/person-info/' ) ) )?>">Read more</a>
And updating functions.php:
function add_custom_query_var( $vars ){
$vars[] = "n";
return $vars;
}
add_filter( 'query_vars', 'add_custom_query_var' );