0
votes

I will try to explain my problem simply and quickly:

I used CPT UI in Wordpress to create my own type of posts - employees. Each employee has an ACF field: email, name, description. On the team of employees page, I display all people with e-mail, photo and name. Each person is in a box, which is a link to separate subpages.

Each sub-page should contain an additional description of the selected employee.

I can't create a link from the team page that will open the subpage of the person you clicked on.

On the team page ( # is the link to subpage of employee):

<?php $count = 1; ?>
          <?php $loop = new WP_Query( array( 'post_type' => 'team', 'orderby' => 'post_id', 'order' => 'ASC' ) ); ?>
          <?php while( $loop->have_posts() ) : $loop->the_post();  ?>
            <div class="col-lg-3 col-sm-6">
              <a href="#" id="person-<?php echo $count; ?>" class="team-item">
                  <img src="<?php the_field('team_photo'); ?>">
                  <p><?php the_title(); ?></p>
                  <p><?php the_field('stanowisko'); ?></p>
                  <p><?php the_field('adres_email'); ?></p>
                  <p></p>
                </a>
            </div>
            <?php $count++; ?>
          <?php endwhile; ?>

Of course, the subpage is a template called page-person.php

I tried to send the post ID of the box, which is currently clicked, to page-person.php, but I do something wrong in the link design:

<a href="<?php bloginfo('stylesheet_directory'); ?>/page-person?post_id=<?php the_ID(); ?>" id="person-<?php echo $count; ?>" class="team-item">

after clicking on the box I get an error in the line: get_header (); the subpage file.

Fatal error: Uncaught Error: Call to undefined function get_header() in 
1
Not completely clear as to how things are setup or what you require. I have answered with my best understanding of what your setup and outcome should be. - Daniel Vickers

1 Answers

0
votes

It seems that you're over complicating it, so you have a custom post type of which is a member of staff meaning each staff is a single post. This means each post has its own URL. Just put that URL as the href link using the_permalink:

<a href="<?php the_permalink();?>" id="person-<?php echo $count; ?>" class="team-item">

And then for the template, just make sure your code for individual profiles is used in that custom post types template file. Job done.