Welcome to the Treehouse Community
Looking to learn something new?
Andrew Folts14,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...
Create a page template and add a custom field on each page with a key to tell the template which post type to get.
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?
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.