Originally published at
jasonackerman.com. You can comment here or
there.
I don’t usually blog about this stuff, but during the day I spend my time picking around WordPress trying to come up with new and cool ways to use it, both for myself and for my clients. Today, I was working on a custom plugin that required me to build a select list for all 50 of the United States. This was a bit tedious, so I’m offering up the code block as it is for you to use if you’d like. The only purpose here is to give you a block of code and save you some typing. Perhaps there’s a better way to build this list, but probably not. If you ever need a drop-down list of states to choose from in your WP custom post type or plugin, here’s a block you can start with. Now you’ll see that I have it checking for “my_fields” … I’ve dumped all of the fields for that custom post type into an array, then I’m checking to see if one of them has been saved so it keeps the correct one selected. There’s plenty more code to accomplish those functions, but this little doozy just has the
tags filled out for all 50 states. It should at least give you a good starting point. And since it’s long, you’ll have to click on the “Continue Reading” link to get to the code snippet. I’ll field any questions in the comments section if I can, but you’re better off just waiting until the plugin is complete and released into the wild, then you can have the whole thing!
Read the rest of this entry »