Easy Content Types makes it really easy to create custom meta boxes with as many fields as you want. Did you know you can use these fields to control the layout of your posts or pages in WordPress? With just a couple of fields, and some tweaks to your theme’s template files, you can provide yourself (or your authors) drastically higher levels of controls over how the content is displayed on the front end.

  1. xefned

    This is fucking cool.
    I was delighted to discover that this works, not only in single.php, but also in header.php. (I didn’t think ECPT fields would be *available* to WP that early.)

    The REALLY cool thing about this is you can include or exclude different javascript and styles to customise the page in more profound ways depending on what fields the client has populated.

    Normally I use Nathan Rice’s “Single Post Template” to achieve this but with ECPT, I can kill two birds with one plugin.

    Also for readers like me struggling to make out the php code in the video, it’s:

    if (get_post_meta($post->ID, ‘ecpt_youtubeid’, true)) { }
    (change youtubeid with your field name)

    • Pippin

      🙂 Glad you like it, and thanks for helping to clarify the code.

      Sorry for being so slow in replying. Your comment got marked as spam 🙁

  2. Matth

    must’ve been the f-word.

  3. Dannymh

    Umm WOW. that is so good. I may actually be able to use custom post types and meta to achieve what I was going to write in a plugin. I can extract the data from the posts into exactly what I need. WOW.

    One thing, can you use the “Get_post_meta()”, outside of the themes? i.e. can I create a plugin to do certain actions on the post meta.

    Your site is an absolute wealth of information!

    • Pippin

      Yes, you can use get_post_meta() in plugins 🙂

  4. Dannymh

    excellent, do the custom fields get sent as part of the $post variable?

    It doesn;t make that much difference, but if I can use $post->custom_field_name on “publish_post” hook, just one of those things again trying to avoid as many overheads as possible and to me calling an additional function is an overhead, with that said I am just about to var dump the $post variable 🙂

    • Pippin

      No, the post meta fields are stored in a separate table in the database. You need to use the get_post_meta() to retrieve the meta values for a particular post ID. You would do something like this:

      $meta = get_post_meta($post->ID, ‘your_meta_field_name’, true);

    • Dannymh

      That doesn’t seem to work on publish_post action or on ‘pre_post_update’ as obviously the post hasn’t been saved yet.

      Basically what I am trying to do is, a user submits a post for review, once reviewed an editor publishes it which triggers my function that then inserts some of this data into another storage table, so for instance one of my fields is “Source Author” I put that into another table so i get a list of source authors which I can then re-use with just their ID’s

      however within this function get_post_meta($post->ID, ‘mediasource’, true) is returning null

    • Pippin

      The “save_post” action should work just fine for you.

    • Pippin

      Try now.

Comments are closed.