Author: Jesse Friedman

Jesse Friedman has been building websites for 20 years, and exclusively with WordPress since 2006. Jesse has written several books, taught 100’s of students as a professor, and organized dozens of local meetups along with a few WordCamps. Jesse has spoken at tech conferences around the world including SXSW, HOW, Future events and many more; and has consulted for a wide array of companies from small agencies to multi-billion dollar international companies. Today Jesse is a proud team member of Jetpack at Automattic, where he spends his time working on partnership and marketing strategies.

Creating a Dropdown Custom Meta Field in WordPress

Here’s a helpful snippet. Let’s say you want to add a State dropdown as a custom meta field on a post, page or custom post type. It can be kind of a pain but if you add the names and values as key value pairs you can loop through the array and output the HTML pretty easily.

First get the value of _cpt_state (if it has one) and assign it to $state

if ( ! $state = get_post_meta( $post->ID, '_cpt_state', true ) ) $state = '';