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?
Share Improve this question asked Oct 22, 2018 at 19:53 BluLotusBluLotus 12 bronze badges 8- I'm not sure I understand your question, maybe you could provide some more details (or an example)? – Pim Commented Oct 22, 2018 at 20:08
- @Pim For example, I have a page and I'm using acf field group that holds data related to each person. I'd like to have a link under that person (on the initial page) that goes to a new page that shows more information about that person. So the field group contains the person name, age, hobbies, and career. On the Initial page it will show name and age, and a link saying something like 'read more' that will go to another page that has more of the person info from the field group - hobbies and career. – BluLotus Commented Oct 22, 2018 at 20:21
- I know I can make a page for each person but I was wondering if there is a way to do this without hardcoding a page for each person as more people can be added. – BluLotus Commented Oct 22, 2018 at 20:22
- I don't immediately see a way you could do this. Maybe you could have a "read more" that displays more info with jQuery on the same page? Not sure that's what you want to achieve by displaying this on a second page. – Pim Commented Oct 22, 2018 at 20:26
- ah ok, I would need to link to a new page. Thanks, for the suggestion though – BluLotus Commented Oct 22, 2018 at 20:31
2 Answers
Reset to default 0You 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' );