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

Posted on

Custom Field Labels In Modified WooThemes Templates

We have recently been playing with WooThemes, in particular their Listing theme. It is a great starting point but, as usual, we want more from it. So we’ve started hacking together our own child theme based on the Listing Theme to drive our upcoming Premium WordPress Plugins website. During this process we learned that some things are easy to modify, some are a little more daunting. Like fetching the custom label you added to a custom field via the WooThemes admin panel. Here is how we did it.

Step 1: Build A Map

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

Now that we have our map we can utilize this to get to the labels (or any other data) that are in the main object. In fact we are using the map because we do have some other elements we want access to for another part of the project. If you want the labels and nothing else you could easily store the label versus the key name into the map and eliminate some extra array lookup overhead. In our case we want the full map, so to output the label we now do this:

<?php echo $woo_metaboxes[$woo_map['purchase-url']]['label']; ?>

 

 

Hope that info helps some fellow WooThemes users out there