Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Andrew Folts
Andrew Folts
14,238 Points

What's the best way to add custom fields to Wordpress archives?

It seems there's two ways to do this, and BOTH kind of suck...

  1. Create a page template and add a custom field on each page with a key to tell the template which post type to get.

  2. Use archive.php and get fields for specific archive pages by storing the info in an option page somewhere.

These aren't great solutions, because they both rely on setting a key or getting a field based on the archive name, so if you change one of those, your scheme is screwed.

How do other people handle this? Any better ideas?


1 Answer

Hi Andrew,

This is very situational. Can you give more detail on the end goal?

Generally, when I have to do something similar I will use the ID of a given author, category etc to change the template this allows more flexibility as well if you change somethings up.

Example - Slug changes or Author name changes, using the ID avoids this breaking it.

Andrew Folts
Andrew Folts
14,238 Points

This always happens, haha. Literally right when your comment came in, I was messing around with ACF and realized you can actually add custom fields to taxonomy term pages.

It's a bit annoying, because it seems you have to set a field location rule to all terms individually, but maybe there's a workaround.