Posted on

Custom Field Pulldown Values, WooThemes Part 2.

This is a follow-on to the article related to custom fields in the WooThemes Listing theme. The second problem we had was that custom fields setup as a drop down were showing the selected index ordinal versus the text value of the selection. Here is how we got to the option value set in the admin panel.

Step 1: Build A Map (repeated from first article)

Rather than consume a lot of extra memory copying objects around, we decided to create a simple map of our custom field labels to the array index provided by the woo_custom_template object that is retrieved from the WordPress database. The main WooThemes plugin uses the $woo_metaboxes variable to store the named array of custom fields data, so we’ll do the same. This code builds an easy-to-use map of labels to the corresponding entry in the $woo_metaboxes object.

// Build a map of custom field names to the
 // corresponding woo meta box object
 $woo_map = array();
 $woo_metaboxes = get_option( 'woo_custom_template' );
 foreach (array_keys($woo_metaboxes) as $wm_keyname) {
     if ($wm_keyname <= '9') {
         $name = $woo_metaboxes[$wm_keyname]['name'];
         $woo_map[$name] = $wm_keyname;

Step 2 : Use The Map

Here is how we access the pulldown values:

<?php  echo $woo_metaboxes[$woo_map['type']]['options'][$csl_type]; ?>

Hope that info helps some fellow WooThemes users out there

One thought on “Custom Field Pulldown Values, WooThemes Part 2.

  1. thanks… for sharing..

Comments are closed.