0
votes

I have created a custom field called "team member" with different labels to develop 7 different team member pages.

However, when I click on each of the member, they take me to a blank page with just header and footer. Looks like they are using the template single_Post.php. How can I point the custom fields to a custom php template in the wordpress so that I can have one team member per page whenever I fill up the Team custom field in the back end.

<?php /* Template Name: Team */ 
get_header(); 

the_post();

 $team_posts = get_posts( array(
'post_type' => 'team',
'posts_per_page' => 1, // Unlimited posts

 ) );

if ($team_posts):
 ?>




 <div id="TeamBanner">
 <?php
     foreach($team_posts as $post):
     setup_postdata($post);
           $image = get_field('banner_image');
                if( !empty($image) ):

   ?>
    <img src= "<?php echo $image['url'];?>" alt="<?php echo       $image['alt']; ?>"/>


   <div id="innerbannerText" style="width:100%;">
    <h1><?php the_field('member_name'); ?></h1>
   <h3>
       <i><?php the_field('member_subheading'); ?></i>
   </h3>
   <p> <span> <?php the_field('team_content'); ?> </span> </p>

  <?php endif; ?>

 <?php endforeach; ?>



 </div>

 <?php endif; ?>

 </div>
1
Have you created the template for the post_type?.. single-team.php - Gabriel Intriago
Yes. I have a template called custom-teampage.php. But how would I Link the Custom fields to that template. Right now they are just linked to singlepost.php template. - user8254869
name it single-team.php since post_type is 'team' and WordPress will look for that page template when you visit a post of the team post type. - TurtleTread

1 Answers

0
votes

Jon,

In this case, there are a couple of things you need to be aware of

Firstly, from the query above

$team_posts = get_posts( array(
'post_type' => 'team',
'posts_per_page' => 1, // Unlimited posts

 ) );

Your custom post type is called team. So what you need to do is (following the guide here - https://developer.wordpress.org/themes/basics/template-hierarchy/) to rename your custom-teampage.php file to single-team.php

This should sort your problem out. However, you may receive a 404 error when you try to look at one of your team pages. If this happens - follow this guide here: https://wordpress.stackexchange.com/questions/202859/custom-post-type-pages-are-not-found

Hopefully this will solve your problem