Steve Taylor photo

Custom fields for custom post types

I’ve just updated my most popular post, Control Your Own WordPress Custom Fields. It’s a long-overdue change, which allows for custom post types.

One thing is, as far as I can tell, when you set properties in PHP classes, you can’t use “dynamic” values. In the new version, there’s a property called $postTypes. I wanted to use get_post_types() to dynamically include public custom post types as well as the standard “post” and “page”, but I kept getting “unexpected (” errors. For now, I’ve hard-coded an array that can be added to. Does anyone know a more elegant solution? The only thing I can think of is using a method, though maybe I’m misunderstanding what I’m doing in terms of using a property.

Anyway, I’ve re-opened the comments over there, so do chip in with ideas!