Skip to toolbar

Step 4: Using Author.php To Show Custom Fields

Now its time to display these fields in the front-end. In this step we will add to, or create the author.php template so it shows information about the author and their posts.

Now it’s time to output all of the fun meta data we created in the previous step. If your theme has an author.php template, open it up in your editor. If not, copy author.php from Twenty Twelve, which is the theme I am editing for this tutorial. Normally author.php is used to display all of the posts by an author. Before you start, you should decide if you want to wipe out all of that or not. I will keep it in so that author.php can serve both its original purpose and its new role as a profile page. If you’re keeping it, make sure to do everything we are about to do between the_post and rewind_posts.

Before we start let’s get all of the information we need together. To get all of our user meta data we will pass the ID of the current author to get_userdata using get_the_author_meta and store the information in an array called $user. From there we will put all of the different pieces of data we need into variables we can echo later. To do this, right after the familiar if ( have_posts () ) : at the beginning of the loop let’s do this:

We could be using pods_display to return the value of the fields we created with Pods. The reason I chose to use get_userdata to populate $user is that it has all of the meta values we need from WordPress generated fields and those we added with Pods. This is possible because Pods, with the exception of when we are using Advanced Content Types uses the standard WordPress tables to store data.

Now that we have all of the information about the user we need in these variables we can echo them as needed to create a profile. Below is an example of how to do this with minimal styling.  The only thing out of the ordinary is the working with the avatar field. I am using pods_image_url to get the address of the large version of the image that I am using to create a link to the image itself, and pods_image to return an image tag for the thumbnail that is displayed in the profile.


After that you can rewind_posts and loop through the author’s posts, or you can end your loop and be done. Your complete author.php will look something like our example.

IMPORTANT NOTE: Only users that have published posts have author pages. We will address this in the next step.

Continue to Step 5: Creating a List of Users and Profile Page