Processing Custom Post Type Content in WordPress

I’m using WordPress custom post types in a project right now, which requires a number of new content sections that are similar to the_post(). In the WP back end, the new content panels are created using add_meta_box() with the TinyMCE WYSIWYG editor so that HTML can easily be added to the content. However, since I have to retrieve the meta box content using get_post_meta(), none of the usual content filters are applied, so we just get the text and any hand-entered HTML, but no automatic paragraph and line break tags or shortcodes. In this case, we need to run the following code on those pieces of content:

echo apply_filters('the_content',$content);

Often when I post code related bits here, it’s for future reference for myself. I know I’m going to need this again, so I know to look for it here.

Changing Credit Card Expiration Date Fields in Shopp

The question was asked in the Shopp Community Forums about how to change the Credit Card expiration date fields from input boxes to drop down menus. The default Shopp template has them set as text boxes, which works fine, but we can improve on this and make it easier to use.

Credit card expiration date text boxes

If you’re using Shopp’s theme templates, you’ll want to edit checkout.php. Look for the following code near the bottom of the file:

<span><?php shopp('checkout','billing-cardexpires-mm','size=4&required=true&minlength=2&maxlength=2&title=Card\'s 2-digit expiration month'); ?> <label for="billing-cardexpires-mm">MM</label></span>
/<span><?php shopp('checkout','billing-cardexpires-yy','size=4&required=true&minlength=2&maxlength=2&title=Card\'s 2-digit expiration year'); ?><label for="billing-cardexpires-yy">YY</label></span>

Change it to the following:

<span> 
  <select id="billing-cardexpires-mm" class="required paycard" title="Card's 2-digit expiration month" name="billing[cardexpires-mm]">
    <option>01</option> 
    <option>02</option> 
    <option>03</option> 
    <option>04</option> 
    <option>05</option> 
    <option>06</option> 
    <option>07</option> 
    <option>08</option> 
    <option>09</option> 
    <option>10</option> 
    <option>11</option> 
    <option>12</option> 
  </select>
  /<label for="billing-cardexpires-mm">Month</label>
</span>
<span>
  <select id="billing-cardexpires-yy" class="required pay card" title="Card's 2-digit expiration year" name="billing[cardexpires-yy]">
<?php 
$thisyear = date("y"); 
for($x=0;$x<10;$x++){ echo '<option>'.($thisyear + $x).'</option>\n'; } ?> </select>
<label for="billing-cardexpires-yy">Year</label></span>

Now you should have a couple of nice drop down select menus, which are a little more user friendly because they eliminate the chance of a user putting in the wrong information. The new code will also display the current year and the next 10 years, which means you won’t need to change the menu code every year.

Credit card expiration date fields drop down menus

Google Web Fonts with Hawaiian Diacritics

Google Web Fonts is a pretty awesome service, considering it’s a free alternative to the larger font collections of TypeKit (also an awesome service).

Embedded web fonts are great, but the Hawaii web design has a dilemma. A lot of place names use Hawaiian diacritics (āēīōūĀĒŌŪĪ) and any time you use the language on a web site there’s a good chance you’ll use a few of these characters. The problem is that not a lot of fonts include these glyphs in their character sets, so we’re limited to the ones that do. This is further complicated by fonts that don’t also include styles for italic, bold, or bold italic.

Google Web Fonts currently has a total of 22 fonts out of 229 that have the Hawaiian diacritics, which is roughly 10%. Of these, only 10 fonts include all font styles.

  • Andika
  • Anonymous Pro *
  • Anton
  • Caudex *
  • Didact Gothic
  • EB Garamond
  • Forum
  • Francois One
  • Gentium Basic *
  • Istok Web *
  • Jura *
  • Kelly Slab
  • Medieval Sharp
  • Modern Antiqua
  • Neuton *
  • Open Sans *
  • Open Sans Condensed *
  • Play *
  • Ruslan Display
  • Tenor Sans
  • Ubuntu *
  • Varela

* fonts support bold, italic, and bold italic

A day without email

I flubbed my DNS records on Friday, thinking that I was getting ready to move my work site from Dreamhost to MediaTemple (since I’ve been having email delivery problems on Dreamhost; too many spammers on their shared servers). So I switched my name servers on Friday afternoon without the proper MX records… Long story short; I haven’t received any email since Friday afternoon.

Normally I don’t screw this process up (since I’ve done it probably 50 times in the past 2 years), but I was rushing when I did it Friday afternoon. I had myself convinced on Monday morning that it was just a slow weekend, and no one had anything to send me. Then I remembered that I tried to send email to myself Friday night, and puzzled over why it never got thru. Mystery solved.

It’s been frustrating waiting for the old DNS records to expire on the Media Temple server so I can enable mail services. I’m used to communicating primarily thru email, and being unable to do that all day has been driving me nuts!

.htaccess forcing larger file uploads

So this is something that I should have memorized by now, but always find myself searching Google whenever I need it. MediaTemple’s Grid Servers have a built in 2mb limit on file uploads, which is small when you’re trying to upload photos from new multi-megapixel cameras, or even just large PDFs. The solution is to drop the following code into the .htaccess file in the root directory:

php_value upload_max_filesize 20M
php_value post_max_size 20M

This next bit usually helps if the uploads are timing out.

php_value max_execution_time 200
php_value max_input_time 200

This usually does the trick!

.htaccess forcing www in urls

I’m starting to use this site as a resource for myself, because I use this stuff all the time, but not enough to commit it fully to memory.

That said, something that’s come up a lot recently is forcing www. in front of all urls on a site. Since all of my servers are Apache, with mod_rewrite enabled, this is no problem. Create an .htaccess file and drop this code into it:

RewriteEngine On
# force www in url
RewriteCond %{HTTP_HOST} !^www\.chrisrunnells\.com [NC]
RewriteRule ^(.*)$ http://www.chrisrunnells.com/$1 [R=301,L]
# END force www in url

The other thing I’ve started doing is using 301 redirects when launching a new site. I can’t believe I didn’t use this years ago! Just add the following to the .htaccess file:

redirect 301 /oldpage.htm http://www.chrisrunnells.com/

And voila, the server redirects the user, and the search engines index the new page as the old one.